我想创建一个由8个按钮组成的布局(四行,两行一行)。使用按钮填充屏幕尺寸的布局
我希望按钮能够按比例填充屏幕大小 - 相等的边距,以便适合不同的屏幕尺寸。
这是我现在有:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/test_1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_marginLeft="10dp" >
<Button
android:id="@+id/concession_btn"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/mybutton" />
<Button
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/concession_btn"
android:text="test2"
android:layout_weight="1"
android:background="@drawable/mybutton" />
<Button
android:id="@+id/test_2"
android:layout_width="150dip"
android:layout_below="@+id/concession_btn"
android:layout_height="wrap_content"
android:text="test3"
android:layout_weight="1"
android:background="@drawable/mybutton"/>
<Button
android:layout_width="150dip"
android:layout_toRightOf="@+id/test_2"
android:layout_below="@+id/concession_btn"
android:layout_height="wrap_content"
android:text="test4"
android:layout_weight="1"
android:background="@drawable/mybutton" />
<Button
android:id="@+id/test_3"
android:layout_width="150dip"
android:layout_below="@+id/test_2"
android:layout_height="wrap_content"
android:text="test3"
android:layout_weight="1"
android:background="@drawable/mybutton"/>
<Button
android:layout_width="150dip"
android:layout_toRightOf="@+id/test_3"
android:layout_below="@+id/test_2"
android:layout_height="wrap_content"
android:text="test4"
android:layout_weight="1"
android:background="@drawable/mybutton" />
<Button
android:id="@+id/test_4"
android:layout_width="150dip"
android:layout_below="@+id/test_3"
android:layout_height="wrap_content"
android:text="test3"
android:layout_weight="1"
android:background="@drawable/mybutton"/>
<Button
android:layout_width="150dip"
android:layout_toRightOf="@+id/test_4"
android:layout_below="@+id/test_3"
android:layout_height="wrap_content"
android:text="test4"
android:layout_weight="1"
android:background="@drawable/mybutton" />
</RelativeLayout>
这给了我八个按钮 - 连续4行中的两个,但我的XML使用固定的利润率所以不会FITT以及对不同势屏大小。
帮助将非常感谢!
请尝试将布局和各分割布局插入按钮.. – Lal
见我的回答@MichaelA – Lal