Android tabcontent包含scrollview,它隐藏了标签后面的内容

时间:2011-11-22 18:49:00

标签: android scrollview android-tabhost

我有一个包含Tabhost的布局。标签位于屏幕的底部。第一个选项卡启动一个ActivityGroup。该ActivityGroup中的第一个活动包含一个scrollview。当内容显示在滚动视图中并且您完全向下滚动时,滚动视图的底部将隐藏在选项卡后面。任何想法如何解决这个问题?

当我启动活动组时,我使用此代码:

Window window = getLocalActivityManager().startActivity(pActivityClass.getName(), intent);
setContentView(window.getDecorView());

装饰是否可以查看整个屏幕?我只是希望视图成为tabcontent。 这是主要布局:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_alignParentTop="true"/>
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>
</RelativeLayout>
</TabHost>

以下是tabcoltent中我想要的视图:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<RelativeLayout android:id="@+id/myLayout" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="16sp"/>

        ... a bunch of other components ...

</RelativeLayout>
</ScrollView>

4 个答案:

答案 0 :(得分:4)

修复您的布局,使内容视图适合标签窗口小部件,而不是填充整个父容器,告诉它布局为RelativeLayout的完整大小,然后放置TabWidget在上面。更像是这样:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@android:id/tabhost"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
<RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@android:id/tabs"/>
  <TabWidget
    android:id="@android:id/tabs"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"/>
</RelativeLayout>
</TabHost>

我还删除了一些不必要的内容,例如android:orientationRelativeLayout内没有任何内容。

HTH

答案 1 :(得分:1)

最佳结果。

android:minWidth = 增加...的值


    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

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

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

            <TabWidget
                **android:minWidth="480dp"**
                android:id="@android:id/tabs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

            </TabWidget>

            </HorizontalScrollView>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>
        </LinearLayout>
    </TabHost>

答案 2 :(得分:1)

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs"/>

这里的关键是

android:layout_above="@android:id/tabs"

答案 3 :(得分:0)

我知道可能有一种“正确”的方式来做到这一点,但我刚刚添加了

<LinearLayout android:layout_width="fill_parent"
        android:layout_height="50dp"></LinearLayout>

到我正在加载到选项卡的xml文件的底部。

另外user1060374是正确的,FrameLayout需要在Tabwidget之上,否则如果内容需要滚动,则scrollview将隐藏(位于顶部)tabbar。 但这样做不会回答你的问题,所以我添加了填充。

相关问题