【问题标题】:adapt bottom menu to all screens使底部菜单适应所有屏幕
【发布时间】:2013-10-17 23:33:48
【问题描述】:

我在 mu android app 中设计了一个底部菜单

它在我工作的屏幕上运行良好

但是如果我更改屏幕,即使我将 relativeLayout 的宽度设置为 fill_parent,它也不会填满屏幕的所有宽度

这里是菜单的代码:

    <RelativeLayout
    android:id="@+id/bar_bas"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:orientation="horizontal" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@null"
        android:clickable="true" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/right_left"
            android:text="test"
            android:textColor="#bfd2b0" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@+id/relativeLayout1"
        android:clickable="true" >

        <Button
            android:id="@+id/btn_circle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/left_circle"
            android:text="test"
            android:textColor="#bfd2b0" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="-40dp"
        android:layout_toRightOf="@+id/relativeLayout2"
        android:clickable="true" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/circle"
            android:text="test"
            android:textColor="#bfd2b0" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="-38dp"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@+id/relativeLayout3"
        android:clickable="true" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/right_circle"
            android:text="test"
            android:textColor="#bfd2b0" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@+id/relativeLayout4"
        android:clickable="true" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/right_left"
            android:text="test"
            android:textColor="#bfd2b0" />
    </RelativeLayout>
</RelativeLayout>

这是我屏幕上的样子:http://s23.postimg.org/m3h37utuj/image.png 这里是其他屏幕(平板电脑屏幕)的示例:http://s24.postimg.org/hd0ibrahh/image.png

我该如何解决这个问题

【问题讨论】:

    标签: android menu width screen fill-parent


    【解决方案1】:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bar_bas"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    
    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#ff00ff"
        android:text="test"
        android:layout_weight="1"
        android:textColor="#bfd2b0" />
    
    <Button
        android:id="@+id/btn_circle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:text="test"
        android:layout_weight="1"
        android:textColor="#bfd2b0" />
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#ff00AA"
        android:text="test"
        android:layout_weight="1"
        android:textColor="#bfd2b0" />
    
    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#ffaaff"
        android:text="test"
        android:layout_weight="1"
        android:textColor="#bfd2b0" />
    
    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#00AAff"
        android:text="test"
        android:layout_weight="1"
        android:textColor="#bfd2b0" />
    
    </LinearLayout>
    

    勾选这个,wrap_parent 表示它会占用尽可能少的空间。

    【讨论】:

      【解决方案2】:

      试试这个..

      <LinearLayout
          android:id="@+id/bar_bas"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:orientation="horizontal" >       
      
              <Button
                  android:layout_height="0dp"
                  android:layout_weight="0.2"
                  android:layout_height="wrap_content"
                  android:background="@drawable/right_left"
                  android:text="test"
                  android:textColor="#bfd2b0" />
      
              <Button
                  android:id="@+id/btn_circle"
                   android:layout_height="0dp"
                  android:layout_weight="0.2"
                  android:layout_height="wrap_content"
                  android:background="@drawable/left_circle"
                  android:text="test"
                  android:textColor="#bfd2b0" />        
      
              <Button
                   android:layout_height="0dp"
                  android:layout_weight="0.2"
                  android:layout_height="wrap_content"
                  android:background="@drawable/circle"
                  android:text="test"
                  android:textColor="#bfd2b0" />       
      
              <Button
                   android:layout_height="0dp"
                  android:layout_weight="0.2"
                  android:layout_height="wrap_content"
                  android:background="@drawable/right_circle"
                  android:text="test"
                  android:textColor="#bfd2b0" />        
      
              <Button
                   android:layout_height="0dp"
                  android:layout_weight="0.2"
                  android:layout_height="wrap_content"
                  android:background="@drawable/right_left"
                  android:text="test"
                  android:textColor="#bfd2b0" />
      
      </LinearLayout>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-12
        • 2017-12-04
        相关资源
        最近更新 更多