这是我正在处理的一个玩具项目的当前主屏幕(.xml 如下):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:text="@string/welcome"
android:gravity="center"
android:layout_weight="3" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dip"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_weight="2" >
<Button
android:id="@+id/resume_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/resume" />
<Button
android:id="@+id/newgame_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/new_game" />
<Button
android:id="@+id/quit_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/quit" />
</LinearLayout>
</LinearLayout>
我得到了我想要的布局,但我做得很好吗?有没有更好的方法来获得这个结果?
其次,假设我想将原始屏幕转换为:
结合通过重力(LEFT
)和填充对齐是一种好方法吗?
提前致谢。