安卓的简单的课程表具体代码
时间: 2023-11-14 13:06:16 浏览: 51
以下是一个简单的安卓课程表的代码示例:
1. 首先在布局文件中添加一个TableLayout控件,用来显示课程表:
```
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/weekdays"
android:stretchColumns="*"/>
```
2. 在Activity中,获取该TableLayout控件,并为其添加课程表数据:
```
TableLayout tableLayout = findViewById(R.id.tableLayout);
// 添加表头
TableRow headerRow = new TableRow(this);
headerRow.addView(createTextView("", 1));
for (int i = 1; i <= 5; i++) {
headerRow.addView(createTextView("星期" + i, 1));
}
tableLayout.addView(headerRow);
// 添加课程表数据
for (int i = 1; i <= 5; i++) {
TableRow row = new TableRow(this);
row.addView(createTextView("第" + i + "节", 1));
for (int j = 1; j <= 5; j++) {
row.addView(createTextView("", 2));
}
tableLayout.addView(row);
}
// 设置课程表数据
setClassData(1, 1, "计算机网络", "教101");
setClassData(1, 2, "操作系统", "教102");
setClassData(2, 3, "计算机组成原理", "教103");
private TextView createTextView(String text, int type) {
TextView textView = new TextView(this);
textView.setText(text);
textView.setGravity(Gravity.CENTER);
if (type == 1) {
textView.setBackgroundColor(Color.parseColor("#B0E0E6"));
textView.setTextSize(18);
} else {
textView.setBackgroundColor(Color.parseColor("#FFFFFF"));
textView.setTextSize(14);
}
return textView;
}
private void setClassData(int week, int section, String className, String classRoom) {
TextView textView = (TextView) ((TableRow) tableLayout.getChildAt(section)).getChildAt(week);
textView.setText(className + "\n" + classRoom);
}
```
以上代码仅为示例,具体实现方式可以根据需求进行调整。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)