Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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_Android Layout - Fatal编程技术网

Android布局问题

Android布局问题,android,android-layout,Android,Android Layout,如何在同一行上有四个按钮的XML布局。我需要第一个和最后一个按钮具有特定宽度(40px),中间两个按钮具有其内容宽度(wrap_content) 示例我想如何定位按钮 |-b1-|…|--b2-|…|--b3-|…|-b4-| 提前谢谢 只需将四个按钮放在水平线性布局中即可。定义布局宽度为40px的b1,布局宽度为包裹内容的b2和b3,然后定义布局宽度为40px的b4。如果要使其居中,只需将LinearLayout的布局宽度设置为“填充父对象”,并使其重心水平。比如: 编辑:哦,如果你想在两边有

如何在同一行上有四个按钮的XML布局。我需要第一个和最后一个按钮具有特定宽度(40px),中间两个按钮具有其内容宽度(wrap_content)

示例我想如何定位按钮

|-b1-|…|--b2-|…|--b3-|…|-b4-|


提前谢谢

只需将四个按钮放在水平线性布局中即可。定义布局宽度为40px的b1,布局宽度为包裹内容的b2和b3,然后定义布局宽度为40px的b4。如果要使其居中,只需将LinearLayout的布局宽度设置为“填充父对象”,并使其重心水平。比如:

编辑:哦,如果你想在两边有两个40px的按钮,中间有两个wrap_内容按钮,你可以选择两种方式。最简单的方法是将一些空白视图添加到LinearLayout(我将在下面演示),而更冗长的方法是使用RelativeLayout并将两个中间按钮放在该RelativeLayout中的LinearLayout中:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_width="wrap_content"
    >
    <Button
        android:layout_width="40px"
        android:layout_height="wrap_content"
        android:text="Button 1"
        />
    <View
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 2"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 3"
        />
    <View
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />
    <Button
        android:layout_width="40px"
        android:layout_height="wrap_content"
        android:text="Button 4"
        />
</LinearLayout>


哇,很久以前了。A假设您已经阅读了这些文档,但我非常确定其中也包含类似的内容。我已经尝试阅读SDK文档,但我找不到我需要的内容…谢谢!这正是我想要的!