[英]How to use a different layout in each ActionBar tab (Android)
我有一個使用Android ActionBar並具有三個標簽的應用程序。 我正在使用一個片段容器來切換不同的ListFragments,但是對於其中一個選項卡,我還想要一個位於布局底部的按鈕和幾個TextView,用於保存列表中數據的摘要。 我在應用程序的其他地方將其作為FragmentActivity和ListFragment來實現。
我想知道是否可以為一個選項卡定義布局?
謝謝
復制您要膨脹ListFragment的布局xml,然后將額外的視圖放在list元素旁邊。 您可以在FragmentActivity中使用onTabSelected(Tab tab, FragmentTransaction ft)
來跟蹤是否選擇了您的特殊情況選項卡,然后將包中的標志推送到實例化您的片段類的位置,然后指示它需要在onCreateView()
。
假設您可能對此布局有此要求:
<?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">
<ListView
android:id="@+id/@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
在此處在列表視圖下面添加TextViews或Button是可行的(在這個確切的示例中,它們確實被推離了屏幕的底部)。 根據您使用ListView進行布局的方式,您可以在列表滾動時將新項持久保存在屏幕底部(RelativeLayout保存所有內容,linearlayout保存文本/按鈕,以及android:layout_above="@+id/idOfThatLinearLayout"
添加為ListView的屬性)。 或者,您也可以使用addFooterView()進行類似的操作,以使這些新項目實際與列表一起滾動,就好像它們是底部的最后一個項目一樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.