Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何排列手机宽度大小相等的按钮?_Android_Xml_Layout - Fatal编程技术网

Android 如何排列手机宽度大小相等的按钮?

Android 如何排列手机宽度大小相等的按钮?,android,xml,layout,Android,Xml,Layout,我试图在XML中排列4个手机宽度大小相等的按钮。我尝试使用相对布局,将它们的关系和按钮的宽度作为“包装内容”。但我面临的问题是,循环关系是不允许的 您可以使用android:layout\u weight使按钮相等,并根据设备屏幕的宽度进行调整。您可以将android:layout\u weight=“1”应用于所有4个按钮。将LinearLayout与android:weightSum=“1.0”一起使用android:layout\u weight=“0.25”并将android:layou

我试图在XML中排列4个手机宽度大小相等的按钮。我尝试使用相对布局,将它们的关系和按钮的宽度作为“包装内容”。但我面临的问题是,循环关系是不允许的


您可以使用android:layout\u weight使按钮相等,并根据设备屏幕的宽度进行调整。您可以将
android:layout\u weight=“1”
应用于所有4个按钮。

LinearLayout
android:weightSum=“1.0”
一起使用
android:layout\u weight=“0.25”
并将
android:layout\u weight=“0.25”
分配给您的4个按钮中的每个按钮(
weight\u sum/no按钮)。

在相对布局下,您提到的线性布局
android:layout\u width=“fill\u parent”android:layout\u weight\u sum=“4”
android:layout\u width=“fill\u parent”所有按钮及其父布局的android:layout\u weight=“1”


这对我很有用。

我想我的回答也会有帮助,尽管这与上述问题没有直接关系。 我想在应用程序的页脚区域安排两个图标。这就是我所做的

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" >

    <ImageButton
        android:id="@+id/back_arrow"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_weight=".5"
        android:background="@android:color/transparent"
        android:contentDescription="@string/Description"
        android:onClick="onClickBtn"
        android:layout_margin="35dp"
        android:src="@drawable/backbut" />

    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight=".5"
         android:layout_margin="35dp"
        android:background="@drawable/copy"
        android:contentDescription="@string/Description"
        android:onClick="onClickBtn" />
</LinearLayout>

因为我想给出相同的宽度,所以我设置了android:layout_weight=“.5”,我想在两个图标之间留一个空白。因此,我设置android:layout\u margin=“35dp”