1
如何使用match_parent通過兩個按鈕分割屏幕寬度。我給match_parent一個按鈕,然後它填充屏幕。我想要兩個按鈕來水平填充屏幕。如何用兩個按鈕分割屏幕?
如何使用match_parent通過兩個按鈕分割屏幕寬度。我給match_parent一個按鈕,然後它填充屏幕。我想要兩個按鈕來水平填充屏幕。如何用兩個按鈕分割屏幕?
你需要使用的重量而不是包裹內容/匹配父母等來劃分的寬度......
所以首先採取了線性佈局給寬度FILL_PARENT,現在加上weighSum屬性爲2
現在,添加2個按鈕與layout_width = 0dp
和在這兩個按鈕添加layout_weight = 1 ....
的完整代碼是在這裏:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="2" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Aamir Shah" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Aamir Shah" />
</LinearLayout>
請使用本網站上的搜索欄 - http://stackoverflow.com/questions/2698817/linear-layout-and-weight-in-android – kellogs