Android布局之LinearLayout自定義高亮背景的方法
更新時間:2016年01月18日 11:32:30 作者:nosxcy
這篇文章主要介紹了Android布局之LinearLayout自定義高亮背景的方法,實例分析了Android中LinearLayout布局參數(shù)設置技巧,需要的朋友可以參考下
本文實例講述了Android布局之LinearLayout自定義高亮背景的方法。分享給大家供大家參考,具體如下:
首先創(chuàng)建linearlayout_background.xml文件
res/drawable/linearlayout_background.xml
<?xml version="1.0" encoding="utf-8"?> <selectorxmlns:android="http://schemas.android.com/apk/res/android"> <itemandroid:state_pressed="true" android:drawable="@drawable/button_pressed"/> <itemandroid:state_focused="true" android:drawable="@drawable/button_pressed"/> <itemandroid:drawable="@drawable/button_normal"/> </selector>
其次在對應的xml布局文件中
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:clickable="true"<!--這條是必須的,否則沒有高亮顯示效果,這有別于自動的button,textview等其他控件-->
android:background="@drawable/linearlayout_background">
<Button ....../>
<TextView ...../>
</LinearLayout>
更多關于Android布局相關內(nèi)容感興趣的讀者可查看本站專題:《Android布局layout技巧總結》
希望本文所述對大家Android程序設計有所幫助。
相關文章
Android使用android-wheel實現(xiàn)省市縣三級聯(lián)動
這篇文章主要為大家詳細介紹了Android使用android-wheel實現(xiàn)省市縣三級聯(lián)動,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08
Android常用控件ImageSwitcher使用方法詳解
這篇文章主要為大家詳細介紹了Android常用控件ImageSwitcher的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08
Android傳遞Bitmap對象在兩個Activity之間
這篇文章主要介紹了Android傳遞Bitmap對象在兩個Activity之間的相關資料,需要的朋友可以參考下2016-01-01
Android實現(xiàn)TextView兩端對齊的方法
這篇文章主要介紹了Android實現(xiàn)TextView兩端對齊的方法,需要的朋友可以參考下2016-01-01

