If you had set that in pixels, size would change because of different screen densities. dp
are used to overcome this situation, so that size is fixed.
If you want your dimensions to change proportionally with the screen size, I think you should use android:weight=
inside a LinearLayout
. I.e.:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="3"
... >
<Button
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="1"
android:text="Button 1" />
<Button
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_weight="2"
android:text="Button 2" />
</LinearLayout>
In this case, Button 1
will always be 1/3 of the LinearLayout
width, while Button 2
will always be 2/3 .
See this pretty popular question.