文章目錄
- 前言
- 示例
- 布局分析
- 實作步驟
- 總結
前言
Android課程表布局實作
我是個菜鳥,文章供參考
示例
圖1:

圖2:
布局分析

該界面主要可分為三部分:
1.顯示年份及周數部分
2.顯示周一到周日
3.課程顯示部分
實作步驟
1.首先整個頁面放在一個LinearLayout布局下面,分為上面和下面兩個部分,下面一個是顯示課程表的詳細資訊
2.將控制元件一個TextView用來顯示年份,一個View用來當作豎線,再用一個LinearLayout用來顯示選擇周數
3.使用ScrollView來顯示課程表的詳細資訊
話不多說直接給代碼!!!
代碼如下:
<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內的內容):
<?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中,
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/162583.html
標籤:其他
下一篇:微信小程式:微信開發者工具匯入wepy-cli生成的專案后控制臺報錯顯示app.json: app.json 未找到
