记得重用layout
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
這樣的布局:
<?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>
還是下邊的布局更容易維護(hù):
<?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>
下邊方式與上邊的區(qū)別就是需要在代碼中去修改一些UI組件的屬性,其實(shí)帶來的復(fù)雜性并不大并且可維護(hù)性上要好很多。以上只是拋磚引玉,Partner作為一個(gè)有工作經(jīng)驗(yàn)的人竟然想不到...
轉(zhuǎn)載于:https://my.oschina.net/kingguary/blog/38026
總結(jié)
以上是生活随笔為你收集整理的记得重用layout的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Andorid X 项目笔记】禁用Li
- 下一篇: ICON资源