Android課程表界面布局實(shí)現(xiàn)代碼
前言
Android課程表布局實(shí)現(xiàn)
我是個(gè)菜鳥,文章供參考
示例
圖1:
圖2:
布局分析
該界面主要可分為三部分:
1.顯示年份及周數(shù)部分
2.顯示周一到周日
3.課程顯示部分
實(shí)現(xiàn)步驟
1.首先整個(gè)頁面放在一個(gè)LinearLayout布局下面,分為上面和下面兩個(gè)部分,下面一個(gè)是顯示課程表的詳細(xì)信息
2.將控件一個(gè)TextView用來顯示年份,一個(gè)View用來當(dāng)作豎線,再用一個(gè)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"> <!--顯示時(shí)間--> <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è)計(jì)@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è)計(jì)@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中寫課程信息。是因?yàn)槲乙獙?shí)現(xiàn)底部導(dǎo)航欄,如果是直接寫一個(gè)界面,可把Fragment內(nèi)的內(nèi)容直接寫在第一個(gè)LinearLayout中。
相關(guān)文章
解決Android SELinux權(quán)限問題記錄分析
這篇文章主要為大家介紹了解決Android SELinux權(quán)限問題記錄分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11Android實(shí)現(xiàn)雙擊TitleBar回頂部的功能示例代碼
一個(gè)簡單易用的導(dǎo)航欄TitleBar,可以輕松實(shí)現(xiàn)IOS導(dǎo)航欄的各種效果,下面這篇文章主要給大家介紹了關(guān)于Android如何實(shí)現(xiàn)雙擊TitleBar回頂部功能的相關(guān)資料,文中給出了詳細(xì)的示例代碼,需要的朋友可以參考借鑒,下面來一起看看吧。2017-09-09Android 2.3 撥號上網(wǎng)流程從源碼角度進(jìn)行分析
SIM卡實(shí)現(xiàn)撥號上網(wǎng)功能之前需要設(shè)置一番,這些設(shè)置步驟究竟做了哪些事情呢?我們現(xiàn)在就從源碼的角度進(jìn)行分析2013-01-01詳細(xì)介紹Android-Room數(shù)據(jù)庫的使用
這篇文章主要介紹了詳細(xì)介紹Android-Room數(shù)據(jù)庫的使用,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03