【问题标题】:How to create a stretchable navigation bar on Android如何在 Android 上创建可伸缩的导航栏
【发布时间】:2011-08-02 17:16:01
【问题描述】:

我正在尝试在屏幕上部创建一个带有 5 个按钮的导航栏。 我希望按钮大小即使在不同的屏幕尺寸上也能保持不变并拉伸到屏幕的宽度。

我找到的最合适的解决方案是表格视图。 问题是我找不到只有一个表格行并以线性视图继续屏幕的其余部分的方法。

在以下示例中,EditText 出现在屏幕底部,而不是直接出现在导航栏之后。

有什么想法吗?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

       <TableRow android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1" android:id="@+id/tableRow2">
           <Button android:layout_width="0dip" android:text="1" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/n1"></Button>
           <Button android:layout_width="0dip" android:text="2" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/n2"></Button>
           <Button android:layout_width="0dip" android:text="3" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/n3"></Button>
           <Button android:layout_width="0dip" android:text="4" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/n4"></Button>
           <Button android:layout_width="0dip" android:text="5" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/n5" android:layout_margin="0"></Button>
       </TableRow>
       <EditText android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:inputType="textPostalAddress">
           <requestFocus></requestFocus>
       </EditText>
</LinearLayout>

【问题讨论】:

    标签: android user-interface navigation uinavigationbar android-actionbar


    【解决方案1】:

    不需要表格布局

    添加LinearLayout

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    
           <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
               <Button android:layout_width="0dip" android:text="1" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/n1"></Button>
               <Button android:layout_width="0dip" android:text="2" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/n2"></Button>
               <Button android:layout_width="0dip" android:text="3" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/n3"></Button>
               <Button android:layout_width="0dip" android:text="4" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/n4"></Button>
               <Button android:layout_width="0dip" android:text="5" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/n5" android:layout_margin="0"></Button>
           </LinearLayout >
           <EditText android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:inputType="textPostalAddress">
               <requestFocus></requestFocus>
           </EditText>
    </LinearLayout>
    

    【讨论】:

      【解决方案2】:

      对于这种类型的布局,您应该使用相对布局,它会自行处理屏幕大小。

      【讨论】:

        猜你喜欢
        • 2018-04-28
        • 2022-10-24
        • 2019-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多