I got a vertical LinearLayout, in which there's a button. I want to make this button 70% of the width of the LinearLayout and center it.
I've tried setting layout_weight
to 0.7 while setting the layout_width
to 0, but since it's a vertical LinearLayout, it doesn't affect the width, but can only affect the height.
How can I change the weight of the width in a vertical layout? Will I must add a nesting horizontal LinearLayout just for the button so I can set its weight?
Try using new PercentRelativeLayout, and you can achieve what you are trying without nested layouts.
include this in your dependencies :
com.android.support:percent:25.1.0
And then in your code