How to select objects in LinearLayout?

I want to create a toolbar that looks like this:

enter image description here

How can I do this in XML? This is what my present looks like:

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/toolbarLinearLayout" android:background="@color/solid_yellow">
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/replyButton" android:text="Reply"></Button>
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RT" android:id="@+id/rtButton"></Button>
        <Button android:id="@+id/dmButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="DM"></Button>
    </LinearLayout>
+3
source share
3 answers

It looks like you might need the LinearLayout add-on attribute, for example.

android:padding="5dip"

To make each element occupy the same space, use layout_weight, for example.

 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/toolbarLinearLayout" android:background="@color/solid_yellow">
    <Button android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/replyButton" android:text="Reply"></Button>
    <Button android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content" android:text="RT" android:id="@+id/rtButton"></Button>
    <Button android:id="@+id/dmButton" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content" android:text="DM"></Button>
</LinearLayout>

As long as all elements have the same weight, they should occupy the same space. layout_width = "fill_parent" will fill the entire line.

+4
source

Define your toolbar like this:

<LinearLayout ...>
    <Button android:id="@+id/replyButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ...
        />
    <View
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        />
    <Button ...
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <!-- etc. -->
</LinearLayout>

All additional space will be allocated to transparent views between the buttons.

+3

android: layout_margin = " " linearlayout. .

0

All Articles