2019独角兽企业重金招聘Python工程师标准>>>
这样的布局:
<?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="fill_parent"
android:orientation="vertical" >
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/hello" />
<LinearLayout android:id="@+id/layout1"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:orientation="vertical"
android:background="#00FF22"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
<LinearLayout android:id="@+id/layout2"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:orientation="vertical"
android:background="#FF9900"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
<LinearLayout android:id="@+id/layout3"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:orientation="vertical"
android:background="#FFFFFF"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
</LinearLayout>
还是下边的布局更容易维护:
<?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="fill_parent"
android:orientation="vertical" >
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/hello" />
<include android:id="@+id/layout1" layout="@layout/layout_item" />
<include android:id="@+id/layout2" layout="@layout/layout_item" />
<include android:id="@+id/layout3" layout="@layout/layout_item" />
</LinearLayout>
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_item" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical"
android:background="#FF0000" android:layout_weight="1">
<TextView android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/hello" />
</LinearLayout>
下边方式与上边的区别就是需要在代码中去修改一些UI组件的属性,其实带来的复杂性并不大并且可维护性上要好很多。以上只是抛砖引玉,Partner作为一个有工作经验的人竟然想不到...