頁面佈局使按鈕按比例顯示 ,水平和垂直

<?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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章