Skip to content Skip to sidebar Skip to footer

Children Views Having Equal Height

I have a horizontal LinearLayout with two buttons with text inside. The LinearLayout's and the buttons layout_height is wrap_content. The text of one of the two buttons takes two l

Solution 1:

I guess what you search is android:baselineAligned="false", this will avoid that the text are on the same baseline and the buttons will start at the same y position on the screen.

Here without android:baselineAligned="false": without android:baselineAligned="false"

And here with: with android:baselineAligned="false"

However if you also want that both buttons are equal sized try this layout example:

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:baselineAligned="false"><Buttonandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:text="aaaaa"/><Buttonandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:text="bbbbbbb bbbbbbbb bbbbbbbb bbbbbbbbbbbb bbbbbb"/></LinearLayout>

That will look like this: enter image description here

Solution 2:

Use this thing to set weigh Sum and weight layout

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:weightSum="100" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="10"android:orientation="horizontal" ><Buttonandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:text="Button 1" /><Buttonandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:text="Button 2" /></LinearLayout></LinearLayout>

Post a Comment for "Children Views Having Equal Height"