Resize buttons in android

I use my layout code as

<LinearLayout android:orientation="horizontal" android:background="@android:drawable/bottom_bar"
    android:paddingLeft="4.0dip" android:paddingTop="5.0dip"
    android:paddingRight="4.0dip" android:paddingBottom="1.0dip"
    android:id="@+id/select_names_tags_ll1"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

    <Button android:id="@+id/button1"
            android:layout_width="0.0dip"
            android:text="ZZZZZZZZZZZZZ"
            android:layout_weight="1.0"
            android:layout_height="wrap_content"
            android:padding="5dp" />
    <Button android:id="@+id/button2"
            android:layout_width="10.0dip"
            android:text="KKKKK"
            android:layout_weight="1.0"
            android:layout_height="wrap_content"
            android:padding="5dp"/>
    <Button android:id="@+id/button3"
            android:layout_width="10.0dip"
            android:text="YYY"
            android:layout_weight="1.0"
            android:layout_height="wrap_content"


android:padding="5dp"/>

his conclusion as enter image description here

I want to fix the width of the buttons, depending on their text length. How will this be possible?

+3
source share
2 answers

You should set the width of the buttons as follows:

android:layout_width="wrap_content"

and you need to remove the following buttons:

android:layout_weight="1.0"
+6
source
android:layout_width="wrap_content"

This should help. For more customization, try using the layout_weight and weightsum attributes

0
source

Source: https://habr.com/ru/post/1793536/


All Articles