Android线性布局按钮对齐

Android线性布局按钮对齐,android,android-layout,android-button,Android,Android Layout,Android Button,我想开发一个类似这样的线性布局。按钮1应获得50%的布局空间,但不应拉伸。我将指定按钮1的宽度。类似地,按钮2和按钮3应该获得剩余50%的布局,我想从布局的右端为按钮2指定左侧填充,为按钮3指定右侧填充 我该怎么做 我当前的代码: <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal

我想开发一个类似这样的线性布局。按钮1应获得50%的布局空间,但不应拉伸。我将指定按钮1的宽度。类似地,按钮2和按钮3应该获得剩余50%的布局,我想从布局的右端为按钮2指定左侧填充,为按钮3指定右侧填充

我该怎么做

我当前的代码:

 <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
     <Button 
       android:layout_height="30dp"
       android:layout_width="fill_parent"
       android:layout_weight="0.5"
       android:text="Button1"
        />
    <Button 
 android:layout_height="30dp"
android:layout_width="fill_parent"
android:layout_weight="0.75"
android:text="Button2"
    />

    <Button 
 android:layout_height="30dp"
android:layout_width="fill_parent"
android:layout_weight="0.75"
android:text="Button3"
    />
</LinearLayout>

您可以使用带有3个按钮的线性布局来实现这一点,只需为按钮添加适当的权重,如下所示:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    <Button
        android:id="@+id/Button01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" android:layout_weight="4"/>

    <Button
        android:id="@+id/Button02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" 
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_weight="1" />

</LinearLayout>

您可以创建两个布局,每个布局增加一个,而不是对按钮进行加权,这样它们将占据屏幕的50%。。然后,您可以根据需要操纵每个布局中的按钮大小

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <Button
            android:id="@+id/button2"

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button3"

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

    </LinearLayout>

</LinearLayout>