頁面佈局使按鈕按比例顯示 ,水平和垂直
阿新 • • 發佈:2019-02-11
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" >//水平排列 <Button android:layout_width="0dp"//水平排列寬度設為0dp
android:layout_height="wrap_content" android:layout_weight="1"//使7個按鈕按1比1佈局 android:text="按鈕1" android:textSize="20sp" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="按鈕2" android:textSize="20sp" > </Button> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="按鈕3" android:textSize="20sp" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="按鈕4" android:textSize="20sp" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="按鈕5" android:textSize="20sp" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="按鈕6" android:textSize="20sp" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="按鈕7" android:textSize="20sp" > </Button> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >//垂直排列
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"//此處比例可以更改
android:text="按鈕1"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="按鈕2"
android:textSize="20sp" >
</Button>
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="按鈕3"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="按鈕4"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="按鈕5"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="按鈕6"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="按鈕7"
android:textSize="20sp" >
</Button>
</LinearLayout>