現在的APP首頁大部分屏幕的下方顯示一行Tab標簽選項,點擊不同的標簽就可以切換到不同的界面。如下圖:
創(chuàng)新互聯(lián)主要從事成都網站建設、做網站、網頁設計、企業(yè)做網站、公司建網站等業(yè)務。立足成都服務鐵東,十余年網站建設經驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:18982081108我們之前都是用TabHost來實現,但是殊不知,TabHost并非是那么的簡單,它的可擴展性非常的差,不能隨意地定制Tab項顯示的內容,而且運行還要依賴于ActivityGroup。ActivityGroup原本主要是用于為每一個TabHost的子項管理一個單獨的Activity,但目前已經被廢棄了。下面就借助Fragment來完成類似于TabHost一般的效果。
先實現主界面布局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="設置" android:textColor="#82858b" /> </LinearLayout> </RelativeLayout> </LinearLayout> </LinearLayout>
分享標題:Androidfragment實現多個頁面切換效果-創(chuàng)新互聯(lián)
地址分享:http://muchs.cn/article22/pdecc.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供自適應網站、外貿網站建設、小程序開發(fā)、App開發(fā)、網站收錄、外貿建站
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容