這篇文章主要為大家展示了“XML文件數減少的示例分析”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“XML文件數減少的示例分析”這篇文章吧。
在android開發中,做出漂亮的ui的應用,往往有數量龐大的xml文件。比如,我們要給一個Button加上一個selector,如果背景不是圖片,就得寫三個xml文件,分別是:
edit_focused.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="3dip" /> <gradient android:angle="90" android:endColor="#ffffff" android:startColor="#000000" android:type="linear" /> </shape>
edit_normal.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="5dip" /> <gradient android:angle="0" android:endColor="#000000" android:startColor="#ffffff" android:type="linear" /> </shape>
selector_edit.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/edit_focus" android:state_pressed="true"></item> <item android:drawable="@drawable/edit_normal"></item> </selector>
一個按鈕的selector就得三個xml,這樣算來,xml文件的數量想少都太難了,其實我們可以把這三個文件合并成一個,寫到一起,這樣就能很大程序上減少讓人眼花繚亂xml文件數。如下:
selector_edit.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape> <corners android:radius="3dip" /> <gradient android:angle="90" android:endColor="#ffffff" android:startColor="#000000" android:type="linear" /> </shape> </item> <item> <shape> <corners android:radius="5dip" /> <gradient android:angle="0" android:endColor="#000000" android:startColor="#ffffff" android:type="linear" /> </shape> </item> </selector>
使用的時候和上面完全一樣。但是xml文件的數量減少很多。
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:background="@drawable/selector_anotate_icon" android:text="@string/btn_text" />
以上是“XML文件數減少的示例分析”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創新互聯成都網站設計公司行業資訊頻道!
另外有需要云服務器可以了解下創新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
分享名稱:XML文件數減少的示例分析-創新互聯
文章來源:http://www.2m8n56k.cn/article34/ccespe.html
成都網站建設公司_創新互聯,為您提供自適應網站、網站內鏈、網站策劃、域名注冊、網站導航、定制開發
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯