for example I want the button's margin to be 1/4 of the screen width (in pixels), what should I do? I prefer to change something in layout xml file instead of coding.
问问题
1544 次
2 回答
3
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="4" >
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
于 2013-01-28T12:26:27.973 回答
0
Use weightSum
and layout_weight
to achieve this.
For e.g
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100"
android:visibility="visible" >
<Button
android:id="@+id/sign_in_button"
android:layout_weight="25"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="testing" />
</LinearLayout>
于 2013-01-28T12:27:59.173 回答