0

我有一个通过扩展此示例获得的简单应用程序(带有片段内容的选项卡):http: //developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html

其中一个选项卡需要有一个 ListView 并且单击一个项目后,如果屏幕很小,则详细信息应显示在另一个屏幕上,如果屏幕很大(或在横向模式下),则应在同一屏幕上显示。

我试图在这里集成这个示例:http: //developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.html,但这是一个活动,而不是一个片段,所以我不能使用:

setContentView(R.layout.fragment_list_layout);

更多细节:

我有一个带有 TabHost 的 FragmentActivity,其内容是片段。其中一个片段必须是 ListFragment,它可以在与列表相同的屏幕上显示详细信息,例如来自 FragmentLayout.java 的示例:

在此处输入图像描述

我想使用推荐的做法(片段作为选项卡内容)来获得这个功能。这可能吗?

如果没有,我已经尝试并设法在选择某个选项卡时启动另一个 FragmentActivity 。目标是使用 FragmentActivity 作为我的布局(ListView + 片段)的容器,就像在 FragmentLayout 示例中一样,除了我似乎无法将之前创建的选项卡菜单添加到它。那么如何让这个工作呢?

目前:

在此处输入图像描述

选择“随机选项卡”后:

在此处输入图像描述

我最后的手段想要的外观(将 FragmentActivity 与原始 tabHost 分开):

在此处输入图像描述

4

1 回答 1

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>

在此之后可以正常处理选项卡。

于 2012-08-17T08:31:08.747 回答