2012-06-18 40 views
0

我有一個簡單的應用程序(帶有Fragment內容的選項卡)通過擴展此示例獲得:http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.htmlAndroid 4.0:使用Tabs + ListView + details的問題

其中一個選項卡需要有一個ListView,並且在單擊一個項目後,如果屏幕很小,或者在同一屏幕上,如果它很大(或橫向模式),則應該在另一個屏幕上顯示細節。

我一直在努力,在這裏這個樣本整合:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.html,但是,一個人的活動,而不是一個片段,所以我不能使用:

setContentView(R.layout.fragment_list_layout); 

LE更多詳細信息:

我有帶有TabHost的FragmentActivity,其內容是碎片。其中一個片段將必須能夠在同一屏幕上顯示的細節列表,比如這個樣品從FragmentLayout.java一個ListFragment:

enter image description here

我想用去這個功能推薦做法(片段作爲標籤內容)。這可能嗎?

如果沒有,我試過並設法啓動另一個FragmentActivity當選擇某個標籤時。目標是使用FragmentActivity作爲我的佈局(ListView +片段)的容器,就像在FragmentLayout示例中一樣,除了我似乎無法將之前創建的選項卡菜單添加到它。那麼如何得到這個工作呢?

目前:

enter image description here

選擇 「隨機選項卡」 後:

enter image description here

我不得已所需的外觀(與原來的tabHost單獨FragmentActivity):

enter image description here

回答

0

我已經解決了這個問題,在我的tabContent中有兩個容器,一個用於ListView片段,另一個用於細節片段。這是我現在的佈局:

<HorizontalScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true" 
    android:scrollbars="vertical" > 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" /> 
</HorizontalScrollView> 

<FrameLayout 
    android:id="@android:id/tabcontent" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_weight="0" /> 

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:baselineAligned="false" 
    android:fadingEdge="none" > 

    <FrameLayout 
     android:id="@+android:id/realtabcontent" 
     android:layout_width="0px" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" /> 

    <FrameLayout 
     android:id="@+android:id/details_container" 
     android:layout_width="0px" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:visibility="gone" /> 
</LinearLayout> 

選項卡可以在此之後正常處理。