Android 如何在FragmentTabHost内部scrollview中构建listview?

Android 如何在FragmentTabHost内部scrollview中构建listview?,android,listview,android-listview,scrollview,Android,Listview,Android Listview,Scrollview,我想构建一个包含FragmentTabHost的Scrollview页面,在FragmentTabHost中我有3个选项卡,每个选项卡都包含带有listview的fragment 例如: 主要活动: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="mat

我想构建一个包含FragmentTabHost的Scrollview页面,在FragmentTabHost中我有3个选项卡,每个选项卡都包含带有listview的fragment

例如:

主要活动

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/Relative1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/Relative1" >

    <RelativeLayout
        android:id="@+id/Relative2"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageButton
            android:id="@+id/ImageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true" />

        <android.support.v4.app.FragmentTabHost
            android:id="@android:id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/ImageButton1" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

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

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

                <FrameLayout
                    android:id="@+id/realtabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1" />
            </LinearLayout>
        </android.support.v4.app.FragmentTabHost>
    </RelativeLayout>
</ScrollView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/listview1"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
>
</ListView>

片段\u示例

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/Relative1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/Relative1" >

    <RelativeLayout
        android:id="@+id/Relative2"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageButton
            android:id="@+id/ImageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true" />

        <android.support.v4.app.FragmentTabHost
            android:id="@android:id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/ImageButton1" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

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

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

                <FrameLayout
                    android:id="@+id/realtabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1" />
            </LinearLayout>
        </android.support.v4.app.FragmentTabHost>
    </RelativeLayout>
</ScrollView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/listview1"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
>
</ListView>

我知道不建议将listview放在scrollview中,最好的方法是将标题添加到列表视图中,但是如何使用FragmentTabHost呢


构建此页面的推荐方法是什么?

想想看。。。你的布局没有意义。。。如果scrollview的高度/宽度与父级匹配,并且选项卡主机内部的高度/宽度与父级匹配,则scrollview是冗余的(高度/宽度-取决于scrollview是水平还是垂直)。您是对的,拉伸listview的尝试失败了,但这不是重点,我想知道构建此页面的建议结构是什么,可能没有在scrollview中插入listview。这里的问题是FragmentTabHost。