I’m trying to set a button to 60% height and 60% width of the physical device.
Since the size of the screen is user-dependent, using dips is out of the question.
How can we do percentage height and width in Android? E.g.:
<Button android:layout_width="60%" android:layout_height="60%"/>
You can use the
layout_weightattribute. If you’ve got the parent layout set to 10 weight, then you can set a weight of 6 in yourButton.There’s quite a bit on the topic on Stack Overflow:
Linear Layout and weight in Android
… or on the official Android blog:
http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html