現(xiàn)在的APP首頁大部分屏幕的下方顯示一行Tab標(biāo)簽選項(xiàng),點(diǎn)擊不同的標(biāo)簽就可以切換到不同的界面。如下圖:
我們之前都是用TabHost來實(shí)現(xiàn),但是殊不知,TabHost并非是那么的簡單,它的可擴(kuò)展性非常的差,不能隨意地定制Tab項(xiàng)顯示的內(nèi)容,而且運(yùn)行還要依賴于ActivityGroup。ActivityGroup原本主要是用于為每一個TabHost的子項(xiàng)管理一個單獨(dú)的Activity,但目前已經(jīng)被廢棄了。下面就借助Fragment來完成類似于TabHost一般的效果。
先實(shí)現(xiàn)主界面布局main_layout.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > </FrameLayout> <View android:layout_width="match_parent" android:layout_height="0.5dp" android:background="#000000" /> <LinearLayout android:layout_width="match_parent" android:layout_height="60dp" android:background="#ffffff" android:orientation="horizontal" > <RelativeLayout android:id="@+id/message_layout" 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" > <ImageView android:id="@+id/message_image" android:layout_width="20dp" android:layout_height="20dp" android:layout_gravity="center_horizontal" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/message_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="消息" android:textColor="#82858b" /> </LinearLayout> </RelativeLayout> <View android:layout_width="0.5dp" android:layout_height="match_parent" android:background="#000000" /> <RelativeLayout android:id="@+id/contacts_layout" 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" > <ImageView android:id="@+id/contacts_image" android:layout_width="20dp" android:layout_height="20dp" android:layout_gravity="center_horizontal" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/contacts_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="聯(lián)系人" android:textColor="#82858b" /> </LinearLayout> </RelativeLayout> <View android:layout_width="0.5dp" android:layout_height="match_parent" android:background="#000000" /> <RelativeLayout android:id="@+id/news_layout" 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" > <ImageView android:id="@+id/news_image" android:layout_width="20dp" android:layout_height="20dp" android:layout_gravity="center_horizontal" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/news_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="動態(tài)" android:textColor="#82858b" /> </LinearLayout> </RelativeLayout> <View android:layout_width="0.5dp" android:layout_height="match_parent" android:background="#000000" /> <RelativeLayout android:id="@+id/setting_layout" 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" > <ImageView android:id="@+id/setting_image" android:layout_width="20dp" android:layout_height="20dp" android:layout_gravity="center_horizontal" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/setting_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="設(shè)置" android:textColor="#82858b" /> </LinearLayout> </RelativeLayout> </LinearLayout> </LinearLayout>
分享標(biāo)題:Androidfragment實(shí)現(xiàn)多個頁面切換效果-創(chuàng)新互聯(lián)
地址分享:http://www.rwnh.cn/article22/pdecc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、小程序開發(fā)、App開發(fā)、網(wǎng)站收錄、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容