Android tabcontent 包含将内容隐藏在选项卡后面的 ScrollView

标签 android scrollview android-tabhost

我有一个包含 Tabhost 的布局。选项卡位于屏幕底部。第一个选项卡启动一个 ActivityGroup。该 ActivityGroup 中的第一个 Activity 包含一个 ScrollView 。当内容显示在 ScrollView 中并且您一直向下滚动时, ScrollView 的底部隐藏在选项卡后面。有什么解决办法吗?

当我启动 Activity 组时,我使用这段代码:

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

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

这是我想要在选项卡内容中显示的 View :

<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>

最佳答案

修复您的布局,使内容 View 适合选项卡小部件上方,而不是填充整个父容器,这告诉它以 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:orientation,它在 RelativeLayout 中什么都不做。

HTH

关于Android tabcontent 包含将内容隐藏在选项卡后面的 ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8232134/

相关文章:

java - 如何通过改造对象中的对象来解析 json 数据?

android - 找不到 Gradle DSL 方法'compile()

android - ScrollView 中的网页 View

java - fragment 无法正常工作

android - 选项卡未按照我的意愿在 Android 中自定义

java - 如何检测另一个方法之外的按钮的单击事件

java - 在两个类之间发送时丢失数据

ios - 如何将 ScrollView 的大小设置为与 View 相同的大小

android - ScrollView 在 ListView 中不起作用

java - Android FragmentTabHost - 尚未完全出炉?