前言
Android课程表布局实现
我是个菜鸟,文章供参考
示例
图1:
图2:
布局分析
该界面主要可分为三部分:
1.显示年份及周数部分
2.显示周一到周日
3.课程显示部分
实现步骤
1.首先整个页面放在一个LinearLayout布局下面,分为上面和下面两个部分,下面一个是显示课程表的详细信息
2.将控件一个TextView用来显示年份,一个View用来当作竖线,再用一个LinearLayout用来显示选择周数
3.使用ScrollView来显示课程表的详细信息
话不多说直接给代码!!!
代码如下:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".Main3Activity"> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" ></FrameLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="60dp" android:background="#FFFFFF"> <RelativeLayout android:id="@+id/layout1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:orientation="vertical"> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="5dp" android:text="周一" android:textColor="#7597B3" /> </LinearLayout> </RelativeLayout> <RelativeLayout android:id="@+id/layout2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:orientation="vertical"> <TextView android:id="@+id/text2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="5dp" android:text="周二" android:textColor="#7597B3" /> </LinearLayout> </RelativeLayout> <RelativeLayout android:id="@+id/layout3" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:orientation="vertical"> <TextView android:id="@+id/text3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="5dp" android:text="周三" android:textColor="#7597B3" /> </LinearLayout> </RelativeLayout> <RelativeLayout android:id="@+id/layout4" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:orientation="vertical"> <TextView android:id="@+id/text4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="5dp" android:text="周四" android:textColor="#7597B3" /> </LinearLayout> </RelativeLayout> <RelativeLayout android:id="@+id/layout5" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:orientation="vertical"> <TextView android:id="@+id/text5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="5dp" android:text="周五" android:textColor="#7597B3" /> </LinearLayout> </RelativeLayout> <RelativeLayout android:id="@+id/layout6" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:orientation="vertical"> <TextView android:id="@+id/text6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="5dp" android:text="周六" android:textColor="#7597B3" /> </LinearLayout> </RelativeLayout> <RelativeLayout android:id="@+id/layout7" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:orientation="vertical"> <TextView android:id="@+id/text7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="5dp" android:text="周日" android:textColor="#7597B3" /> </LinearLayout> </RelativeLayout> </LinearLayout> </LinearLayout>
显示课程表的详细信息代码如下(Fragment内的内容):
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595<?xml version="1.0" encoding="utf-8"?> <!--模仿课程表的界面--> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/qq5"> <!--显示时间--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white"> <TextView android:id="@+id/year" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_gravity="center" android:gravity="center" android:layout_marginLeft="20dp" android:textSize="20dp" android:text="2020-2021"/> <View android:layout_width="1dp" android:layout_height="match_parent" android:layout_marginLeft="20dp" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:background="#00FFFF" /> <TextView android:id="@+id/te1" android:text="第八周" android:gravity="center" android:textColor="@color/colorPrimary" android:textSize="25dp" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#00FF7F"/> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:background="@android:color/white"> <TextView android:layout_width="25dp" android:layout_height="match_parent"/> <TextView android:layout_width="54dp" android:layout_height="match_parent" android:text="周一" android:textSize="20dp" android:textColor="@color/colorPrimaryDark" android:gravity="center"/> <TextView android:layout_width="54dp" android:layout_height="match_parent" android:text="周二" android:textSize="20dp" android:textColor="@color/colorPrimaryDark" android:gravity="center"/> <TextView android:layout_width="54dp" android:layout_height="match_parent" android:text="周三" android:textSize="20dp" android:textColor="@color/colorPrimaryDark" android:gravity="center"/> <TextView android:layout_width="54dp" android:layout_height="match_parent" android:text="周四" android:textSize="20dp" android:textColor="@color/colorPrimaryDark" android:gravity="center"/> <TextView android:layout_width="54dp" android:layout_height="match_parent" android:text="周五" android:textSize="20dp" android:textColor="@color/colorPrimaryDark" android:gravity="center"/> <TextView android:layout_width="54dp" android:layout_height="match_parent" android:text="周六" android:textSize="20dp" android:textColor="@color/colorPrimaryDark" android:gravity="center"/> <TextView android:layout_width="54dp" android:layout_height="match_parent" android:text="周日" android:textSize="20dp" android:textColor="@color/colorPrimaryDark" android:gravity="center"/> </LinearLayout> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="25dp" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:text="一" android:textSize="12dp" android:gravity="center"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/colorPrimaryDark"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:textSize="12dp" android:text="二" android:gravity="center"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/colorPrimaryDark"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:textSize="12dp" android:text="三" android:gravity="center"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/colorPrimaryDark"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:textSize="12dp" android:text="四" android:gravity="center"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/colorPrimaryDark"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:textSize="12dp" android:text="五" android:gravity="center"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/colorPrimaryDark"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:gravity="center" android:text="六" android:textSize="12dp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/colorPrimaryDark"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:gravity="center" android:text="七" android:textSize="12dp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/colorPrimaryDark"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:gravity="center" android:text="八" android:textSize="12dp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/colorPrimaryDark"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:gravity="center" android:text="九" android:textSize="12dp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/colorPrimaryDark"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:gravity="center" android:text="十" android:textSize="12dp" /> </LinearLayout> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#E5E5E5"/> <LinearLayout android:layout_width="54dp" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="185dp" android:id="@+id/o_text1" android:background="#00FFFF" android:text="乒乓球@地下室一层" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/o_tex2" android:layout_width="50dp" android:layout_height="185dp" android:background="#00FFFF" android:text="面向对象程序设计@4号楼" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/o_tex3" android:layout_width="50dp" android:layout_height="185dp" android:background="#00FFFF" android:text="大学体育@A区游泳馆" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/o_tex4" android:layout_width="50dp" android:layout_height="185dp" android:background="#00FFFF" android:text="面向对象程序设计@3号楼" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/o_tex5" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> </LinearLayout > <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#E5E5E5"/> <LinearLayout android:layout_width="54dp" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="185dp" android:id="@+id/t_text1" android:text="高等数学@3号楼" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/t_tex2" android:layout_width="50dp" android:layout_height="185dp" android:text="大学英语@汇文楼" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/t_tex3" android:layout_width="50dp" android:layout_height="185dp" android:text="大学物理@3号楼" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/t_tex4" android:layout_width="50dp" android:layout_height="185dp" android:text="电路与电子技术@3号楼" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/t_tex5" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> </LinearLayout > <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#E5E5E5"/> <LinearLayout android:layout_width="54dp" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="185dp" android:id="@+id/th_text1" android:text="电路与电子技术@4号楼" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/th_tex2" android:layout_width="50dp" android:layout_height="185dp" android:text="大学英语@3号楼" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/th_tex3" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/th_tex4" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/th_tex5" android:layout_width="50dp" android:layout_height="185dp" android:text="形式与政策@汇文楼" android:textSize="23dp"/> </LinearLayout > <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#E5E5E5"/> <LinearLayout android:layout_width="54dp" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="185dp" android:id="@+id/f_text1" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/f_tex2" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/f_tex3" android:layout_width="50dp" android:layout_height="185dp" android:text="电路与电子技术@3号楼" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/f_tex4" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/f_tex5" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> </LinearLayout > <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#E5E5E5"/> <LinearLayout android:layout_width="54dp" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="185dp" android:id="@+id/fi_text1" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/fi_tex2" android:layout_width="50dp" android:layout_height="185dp" android:text="高等数学@3号楼" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/fi_tex4" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/fi_tex5" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> </LinearLayout > <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#E5E5E5"/> <LinearLayout android:layout_width="54dp" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="185dp" android:id="@+id/s_text1" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/s_tex2" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/s_tex3" android:layout_width="50dp" android:layout_height="185dp" android:text="大学生心理健康教育" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/s_tex4" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/s_tex5" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> </LinearLayout > <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#E5E5E5"/> <LinearLayout android:layout_width="54dp" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="185dp" android:id="@+id/se_text1" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/se_tex2" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/se_tex3" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/se_tex4" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#E5E5E5"/> <TextView android:id="@+id/se_tex5" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp"/> <TextView android:id="@+id/fi_tex3" android:layout_width="50dp" android:layout_height="185dp" android:textSize="23dp" /> </LinearLayout > <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#E5E5E5"/> </LinearLayout> </ScrollView> </LinearLayout>
总结
我上面使用了Fragment,在Fragment中写课程信息。是因为我要实现底部导航栏,如果是直接写一个界面,可把Fragment内的内容直接写在第一个LinearLayout中。
最后
以上就是时尚冬瓜最近收集整理的关于Android课程表界面布局实现代码的全部内容,更多相关Android课程表界面布局实现代码内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复