Android開(kāi)發(fā)之merge結(jié)合include優(yōu)化布局
merge結(jié)合include優(yōu)化android布局,效果不知道,個(gè)人感覺(jué)使用上也有很大的局限,不過(guò)還是了解一下,記錄下來(lái)。
布局文件都要有根節(jié)點(diǎn),但android中的布局嵌套過(guò)多會(huì)造成性能問(wèn)題,于是在使用include嵌套的時(shí)候我們可以使用merge作為根節(jié)點(diǎn),這樣可以減少布局嵌套,提高顯示速率。
<?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="張三" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="李四" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="王五" /> </merge>
上面的界面在顯示的時(shí)候會(huì)自動(dòng)嵌套到下面的文件中。
<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="horizontal" tools:context="com.example.viewstub.MainActivity" > <include layout="@layout/top"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <Button android:id="@+id/toggle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClick" android:text="顯示/隱藏" /> <ViewStub android:id="@+id/vs" android:layout_margin="50dp" android:layout_width="match_parent" android:layout_height="match_parent" android:inflatedId="@+id/inflated_id" android:layout="@layout/view_stub_layout" /> </LinearLayout>
我為什么說(shuō)這個(gè)局限性比較大呢?因?yàn)閙erge中的空間顯示的使用會(huì)采用主布局文件的方式來(lái)顯示,比如我這里主布局是linearlayout且是水平排列,那么merge中的元素顯示出來(lái)之后也是水平排列,可是我如果想讓merge中的元素垂直排列呢?抱歉,做不到。
原文鏈接:http://blog.csdn.net/u012702547/article/details/47133647
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)Android軟件編程有所幫助。
相關(guān)文章
Android?模擬地圖定位功能的實(shí)現(xiàn)
這篇文章主要介紹了Android?模擬地圖定位功能的實(shí)現(xiàn),本工程利用手機(jī)自帶的"模擬位置"功能實(shí)現(xiàn)運(yùn)行時(shí)修改LocationManager結(jié)果,需要的朋友可以參考一下2022-02-02
Android數(shù)據(jù)共享 sharedPreferences 的使用方法
這篇文章主要介紹了Android數(shù)據(jù)共享 sharedPreferences 的使用方法的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家理解使用sharedpreferences,需要的朋友可以參考下2017-10-10
Android TextView顯示Html類解析的網(wǎng)頁(yè)和圖片及自定義標(biāo)簽用法示例
這篇文章主要介紹了Android TextView顯示Html類解析的網(wǎng)頁(yè)和圖片及自定義標(biāo)簽用法,實(shí)例分析了Android中TextView控件的使用技巧,需要的朋友可以參考下2016-07-07
說(shuō)說(shuō)Android的UI刷新機(jī)制的實(shí)現(xiàn)
這篇文章主要介紹了說(shuō)說(shuō)Android的UI刷新機(jī)制的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03

