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

时间:2022-03-23 06:18:42

I have a layout which contains a Tabhost. The tabs are at the bottom of the screen. The first tab starts an ActivityGroup. The first activity in that ActivityGroup contains a scrollview. When the contents are displayed in the scrollview and you scroll all the way down, the bottom of the scrollview is hidden behind the tabs. Any ideas how to fix this?

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

When I start the activitygroup, I use this code:

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

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

Is the decor view the entire screen? I just want the view to be the tabcontent. Here is the main layout:

装饰视图是整个屏幕吗?我只是希望视图成为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>

Here is the view I want in the tabcontent:

这是我在tabcontent中想要的视图:

<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 个解决方案

#1


4  

Fix your layout so the content view fits above the tab widget, instead of filling the entire parent container, which tells it to lay out as the full size of the RelativeLayout and then lay the TabWidget on top. Something more like this:

修复你的布局,使内容视图适合选项卡小部件,而不是填充整个父容器,它告诉它布局为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>

I also removed some of the unnecessary items like android:orientation which does nothing inside of a RelativeLayout.

我还删除了一些不必要的项目,如android:orientation,它在RelativeLayout中没有任何作用。

HTH

HTH

#2


1  

Optimal result.

最佳结果。

android:minWidth= Increase the value of...

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>

#3


1  

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

Here, the key line is,

关键在于,

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

#4


0  

I know there might be a "correct" way to do this, but I just added

我知道可能有一种“正确”的方式来做到这一点,但我刚才补充道

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

to the bottom of the xml file I was loading into the tab.

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

Also user1060374 is right the FrameLayout needs to be above the Tabwidget or the scrollview will hide(be on top of) the tabbar if the contents needs scrolled. But just doing this won't answer your question, so I added the padding.

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

#1


4  

Fix your layout so the content view fits above the tab widget, instead of filling the entire parent container, which tells it to lay out as the full size of the RelativeLayout and then lay the TabWidget on top. Something more like this:

修复你的布局,使内容视图适合选项卡小部件,而不是填充整个父容器,它告诉它布局为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>

I also removed some of the unnecessary items like android:orientation which does nothing inside of a RelativeLayout.

我还删除了一些不必要的项目,如android:orientation,它在RelativeLayout中没有任何作用。

HTH

HTH

#2


1  

Optimal result.

最佳结果。

android:minWidth= Increase the value of...

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>

#3


1  

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

Here, the key line is,

关键在于,

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

#4


0  

I know there might be a "correct" way to do this, but I just added

我知道可能有一种“正确”的方式来做到这一点,但我刚才补充道

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

to the bottom of the xml file I was loading into the tab.

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

Also user1060374 is right the FrameLayout needs to be above the Tabwidget or the scrollview will hide(be on top of) the tabbar if the contents needs scrolled. But just doing this won't answer your question, so I added the padding.

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