You could use a RelativeLayout
and the layout_alignLeft
and layout_alignRight
XML attributes to match width (the analogous properties layout_alignTop
and layout_alignBottom
would work for matching height). This only works if you want the views aligned though - otherwise, you'll have to use a dimension resource.
Here's an example with aligned Buttons and matching heights:
<RelativeLayout
...>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/muh_button"
android:onClick="do_stuff"/>
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_toRightOf="@id/button1"
android:layout_alignTop="@id/button1"
android:layout_alignBottom="@id/button1"
android:text="@string/muh_other_button"
android:onClick="do_other_stuff"/>
</RelativeLayout>
Here's an example with a dimension resource:
<SomeViewGroup
...>
<Button
android:layout_width="wrap_content"
android:layout_height="@dimen/button_height"
android:text="@string/muh_button"
android:onClick="do_stuff"/>
<Button
android:layout_width="wrap_content"
android:layout_height="@dimen/button_height"
android:text="@string/muh_other_button"
android:onClick="do_other_stuff"/>
</SomeViewGroup>
where the dimension button_height
is defined in dimens.xml
.