【问题标题】:Android align two buttonsAndroid对齐两个按钮
【发布时间】:2011-06-22 00:00:23
【问题描述】:

我有两个相邻的按钮。我希望它们具有相同的大小并填充屏幕的整个宽度。我一直在尝试使用此代码: (如果重要的话,这是相对布局)

<Button android:text="Names" 
android:id="@+id/Button01" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:layout_weight="1">
</Button>
<Button android:text="Dates" 
android:id="@+id/Button02" 
android:layout_toRightOf="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</Button>

【问题讨论】:

    标签: android alignment


    【解决方案1】:

    在按钮周围包裹一个 LinearLayout?那么你可以根据需要使用填充来调整确切的位置

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    <Button android:text="Names" 
    android:id="@+id/Button01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_weight="1">
    </Button>
    <Button android:text="Dates" 
    android:id="@+id/Button02" 
    android:layout_toRightOf="@+id/Button01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1">
    </Button>
    </LinearLayout>
    

    【讨论】:

    • 这是一个很好的解决方案。完全按需要工作。
    猜你喜欢
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 1970-01-01
    • 2014-02-27
    • 2017-09-24
    • 2021-08-24
    • 1970-01-01
    相关资源
    最近更新 更多