Android安排按钮连续

moh*_*ary 1 android android-layout

我怎么能在这张照片中连续安装一些按钮.
实际上我需要添加或删除按钮之间的空格; 按钮必须稳定.我总是左边有一个按钮,右边有一个按钮,中间有一个按钮,中间有两个按钮.如果屏幕尺寸发生变化,按钮之间的间隙将会改变.

预先感谢

这张照片显示了它如何在小屏幕上工作

在此输入图像描述

图2展示了它在大屏幕中的表现.

在此输入图像描述

按钮"1"始终为左;
按钮"5"始终是对的;
按钮"3"始终为中心;

问题:如何使按钮"2"和"4"始终在其他按钮之间具有相同的空间?

use*_*737 5

这里我展示了4个按钮的配置.我们的想法是将按钮包装在一个水平位置,LinearLayout并在按钮之间添加layout_weight1,以便在线性布局改变大小时缩小和扩展.

<LinearLayout
    android:id="@+id/lh"
    android:layout_width="208dp"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/editText2"
        android:layout_below="@+id/editText2"
        android:layout_marginTop="15dp"
        android:text="B" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </View>

    <Button
        android:id="@+id/Button01"
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:text="B" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </View>

    <Button
        android:id="@+id/Button02"
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:text="B" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </View>

    <Button
        android:id="@+id/Button03"
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:text="B" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

或者,等效地,替换SpaceView传达此特定视图的实际功能,但仅限于使用级别至少为14的API .Space是" 一个轻量级的View子类,可用于在通用布局中创建组件之间的间隙 ".

  • 谢谢; 这就是我真正需要的; (2认同)