android - TabHost 上的相对布局?

标签 android

我有一个 Android UI 问题,我不太确定如何解决。我有一个标签主机,上面有几个不同的项目。在一种情况下,添加到 ScrollView (位于其中一个选项卡上)的字段将被动态添加。我在屏幕底部有一个按钮,使用相对布局。问题是 ScrollView (和其他选项卡的线性布局)超出了底部按钮。这导致屏幕上的最终字段不可见,因为它被按钮隐藏了。这是问题的屏幕截图以及我的布局的 xml。任何帮助是极大的赞赏。 enter image description here

主要布局:

<?xml version="1.0" encoding="utf-8"?>

<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"
    android:background="@drawable/background_nologo" >

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

<TabWidget android:id="@android:id/tabs"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true" />

<View android:layout_width="fill_parent"
    android:layout_height="2dip"/>

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

<include layout="@layout/mc_message_send_tab_details"/>

<!-- Scrollview for message data -->
<ScrollView android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:scrollbars="vertical"
    android:id="@+id/formTab">

<!-- Form fields are automatically 
    created in McMessageViewActivity. -->
<LinearLayout android:id="@+id/formLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <View android:layout_width="fill_parent"
    android:layout_height="5dip"/>

</LinearLayout>
</ScrollView>

</FrameLayout>

</LinearLayout>

<RelativeLayout android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">      
<LinearLayout android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_alignParentBottom="true" >
    <Button android:text="Send" 
        android:id="@+id/btnSend" android:layout_weight="1" 
        android:layout_height="wrap_content" android:layout_width="0px"/>
</LinearLayout>
</RelativeLayout>

</TabHost>

额外的标签布局:

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

    <TableLayout android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:stretchColumns="1">

        <View android:layout_width="fill_parent"
            android:layout_height="10dip"/>

       <TableRow>
           <TextView
               android:text="Unit #"
               android:textStyle="bold"
               android:gravity="right"
               android:padding="3dip" />
           <Spinner android:id="@+id/unitNumber"
               android:text=""
               android:padding="3dip"
               android:layout_marginRight="2sp"/>
       </TableRow>
       <TableRow>
           <TextView
               android:text="User ID"
               android:textStyle="bold"
               android:gravity="right"
               android:padding="3dip" />
           <EditText android:id="@+id/userId"
               android:text=""
               android:padding="3dip"
               android:layout_marginRight="2sp" />
       </TableRow>
       <TableRow>
           <TextView
               android:text="Form #"
               android:textStyle="bold"
               android:gravity="right"
               android:padding="3dip" />
           <Spinner android:id="@+id/formNumber"
               android:text=""
               android:padding="3dip"
               android:layout_marginRight="2sp" />
       </TableRow>
       <TableRow>
           <TextView
               android:text="Sending status"
               android:textStyle="bold"
               android:gravity="right"
               android:padding="3dip" />
           <EditText android:id="@+id/sendingStatus"
               android:text=""
               android:padding="3dip"
               android:layout_marginRight="2sp"/>
       </TableRow>
       <TableRow>
           <TextView
               android:text="Delivery priority"
               android:textStyle="bold"
               android:gravity="right"
               android:padding="3dip" />
           <EditText android:id="@+id/priority"
               android:text=""
               android:padding="3dip"
               android:layout_marginRight="2sp"/>
       </TableRow>
       <TableRow>
           <TextView
               android:text="Request reply"
               android:textStyle="bold"
               android:gravity="right"
               android:padding="3dip" />
           <CheckBox android:id="@+id/requestReply"
               android:padding="3dip"
               android:layout_marginRight="2sp" />
       </TableRow>
       <TableRow>
           <TextView
               android:text="Receipt conf"
               android:textStyle="bold"
               android:gravity="right"
               android:padding="3dip" />
           <CheckBox android:id="@+id/receiptConfirmation"
               android:padding="3dip"
               android:layout_marginRight="2sp" />
       </TableRow>

    </TableLayout>   

</LinearLayout>

最佳答案

您的主要问题是由于 TabHost 扩展了 FrameLayout。这就是您在主布局上使用最后一个 RelativeLayout 的原因。你试图作弊,但你输了……:)

您需要做的是将一个独特的 View (例如 RelativeLayout)放入 TabHost,然后将所有其他 View 放入其中。

类似于以下内容(我必须删除一些 <includes /> 和背景才能使其在我的计算机上运行):

<?xml version="1.0" encoding="utf-8"?>
<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"
        android:padding="5dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true" />
        <View
            android:id="@+id/separator"
            android:layout_below="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="2dip" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_below="@+id/separator"
            android:layout_above="@+id/btnSend"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <!-- Scrollview for message data -->
            <ScrollView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:scrollbars="vertical"
                android:id="@+id/formTab">
                <!--
                    Form fields are automatically created in
                    McMessageViewActivity.
                -->
                <LinearLayout
                    android:id="@+id/formLayout"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <View
                        android:layout_width="fill_parent"
                        android:layout_height="5dip" />
                </LinearLayout>
            </ScrollView>
        </FrameLayout>
        <!--  Unnecessary      <LinearLayout-->
        <!--            android:layout_height="wrap_content"-->
        <!--            android:layout_width="fill_parent"-->
        <!--            android:layout_alignParentBottom="true">-->
        <Button
            android:layout_alignParentBottom="true"
            android:text="Send"
            android:id="@+id/btnSend"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent" />
        <!--        </LinearLayout>-->
    </RelativeLayout>
</TabHost>

关于android - TabHost 上的相对布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7099035/

相关文章:

android - 可以获得总存储容量吗?

android - 在 android studio 中将 UnitTest 转换为 Instrumentation Test

Android AWS S3 安全警报

android - 如何从 TabHost 中删除选项卡

android - 如何删除 RelativeLayout 中按钮之间的空格?

android - 从命令行安装 avd

android - 使用 ACTION_SEND 打开共享对话框以共享文件

android - 无法在我的 Mac 上使用 dex2jar : permission denied

android - 尝试使用 proguard 运行测试

android - 从具有小屏幕/RAM 的设备中隐藏 Google 应用程序