上图中,按钮的大小为屏幕的一半,然后居中显示在布局中央,每个人心中都有自己的答案,看看我的方法吧,布局布局xml如下 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1" > <!-- 1.将LinearLayout的layout_weight设置为1 -->
<!-- 2.将Button的layout_width设为0dp, 并且将layout_weight设置为0.5 -->
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:textSize="13sp"
android:text="@string/button_text" >
</Button>
</LinearLayout> 这里有几个关键点:Android中设置半个屏幕大小且居中的按钮布局 (layout_weight属性),布布扣,bubuko.com
Android中设置半个屏幕大小且居中的按钮布局 (layout_weight属性)
原文地址:http://blog.csdn.net/bboyfeiyu/article/details/38315775