Reputation:
I have a fragment in which i am displaying 4 buttons, in those button I m displaying some texts that I m getting from my sqlite database, after any button click I m refreshing the text on the buttons by getting some other text from the db. What i want is to resize the buttons and set each button's height to the max of the buttons new size (the height will depend on the lengh of the text that is displayed in the button). How can I perform that?
Upvotes: 0
Views: 41
Reputation: 3425
Put all 4 buttons in a linear layout where the orientation="vertical"
and give them each a layout_weight="1"
and a layout_height="0dp"
. This will give you a each button having the same height. You can manage the overall height by adjusting the height of the linear layout. The linear Labour's height must be large enough to contain the buttons
Upvotes: 0
Reputation: 9569
Kickoff example:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
</LinearLayout>
More info - layout_weight.
Upvotes: 3