Android拉伸布局宽度:绝对宽度+百分比

时间:2016-05-06 10:52:11

标签: java android xml

我有2个按钮,第一个按钮应该有100dp宽度,第二个按钮应该是(parent - 100dp)宽度。

这可能实现吗?

我尝试了以下内容:

<android.support.v7.widget.ButtonBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="100dp"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:layout_weight="1"/>
    </android.support.v7.widget.ButtonBarLayout>

1 个答案:

答案 0 :(得分:0)

尝试使用 RelativeLayout 作为父级:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/button1"
        android:layout_width="100dp"
        android:layout_alignParentLeft="true"
        android:layout_height="wrap_content" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/button1" />
</RelativeLayout>
相关问题