Android課程表界面布局實現(xiàn)代碼
前言
Android課程表布局實現(xiàn)
我是個菜鳥,文章供參考
示例
圖1:

圖2:

布局分析

該界面主要可分為三部分:
1.顯示年份及周數(shù)部分
2.顯示周一到周日
3.課程顯示部分
實現(xiàn)步驟
1.首先整個頁面放在一個LinearLayout布局下面,分為上面和下面兩個部分,下面一個是顯示課程表的詳細(xì)信息
2.將控件一個TextView用來顯示年份,一個View用來當(dāng)作豎線,再用一個LinearLayout用來顯示選擇周數(shù)
3.使用ScrollView來顯示課程表的詳細(xì)信息
話不多說直接給代碼!!!
代碼如下:
<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>
顯示課程表的詳細(xì)信息代碼如下(Fragment內(nèi)的內(nèi)容):
<?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="面向?qū)ο蟪绦蛟O(shè)計@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="大學(xué)體育@A區(qū)游泳館"
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="面向?qū)ο蟪绦蛟O(shè)計@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="高等數(shù)學(xué)@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="大學(xué)英語@匯文樓"
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="大學(xué)物理@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="電路與電子技術(shù)@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="電路與電子技術(shù)@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="大學(xué)英語@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="電路與電子技術(shù)@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="高等數(shù)學(xué)@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="大學(xué)生心理健康教育"
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>
總結(jié)
我上面使用了Fragment,在Fragment中寫課程信息。是因為我要實現(xiàn)底部導(dǎo)航欄,如果是直接寫一個界面,可把Fragment內(nèi)的內(nèi)容直接寫在第一個LinearLayout中。
相關(guān)文章
Android解析相同接口返回不同格式j(luò)son數(shù)據(jù)的方法
這篇文章主要介紹了Android解析相同接口返回不同格式j(luò)son數(shù)據(jù)的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08
Android開發(fā)基于ScrollView實現(xiàn)的漸變導(dǎo)航欄效果示例
這篇文章主要介紹了Android開發(fā)基于ScrollView實現(xiàn)的漸變導(dǎo)航欄效果,涉及ScrollView事件響應(yīng)及元素屬性動態(tài)操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2017-12-12
Android使用Notification實現(xiàn)通知功能
這篇文章主要為大家詳細(xì)介紹了Android使用Notification實現(xiàn)通知功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11
android開發(fā)教程之卸載sd卡對MediaServer的處理
Android中如果MediaServer訪問SD卡上的音頻文件,卸載SD卡的時候,就會kill掉MediaServer,卸載SD卡上必要條件就是沒有進(jìn)程訪問SD卡上的資源文件。Kill掉MediaServer的進(jìn)程后,MediaServer會重新啟動。2014-02-02

