新聞中心
在Android中使用focusable 屬性來實現(xiàn)按鈕的特效,看到百威啤酒的客戶端主界面的按鈕,感覺比較新奇,先看下圖片:

我們提供的服務(wù)有:成都做網(wǎng)站、網(wǎng)站制作、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、尚義ssl等。為成百上千企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的尚義網(wǎng)站制作公司
注意圖中我畫的箭頭,當(dāng)時鼠標(biāo)點擊的黑色圈圈的位置,然后按鈕出現(xiàn)了按下的效果(黃色的描邊)
剛開始看到這種效果很是好奇,不知道是怎么實現(xiàn)的,后來仔細(xì)一想,應(yīng)該是整個啤酒罐是一張圖片(ImageView),該圖片是布局在三個按鈕之上,然后就是最關(guān)鍵的地方,把圖片設(shè)置為不可獲取焦點,也就是Android:focusable="false" ,就這樣簡單的一行,就可以搞定了!
為了驗證我的想法,我建了一個工程來做測試,效果如下圖所示:
具體代碼如下:
main.xml:
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/bg2"
- android:focusable="false"
- />
button_selector.xml:
- xmlns:android="http://schemas.android.com/apk/res/android">
- android:width="2dp"
- android:color="#FFFF00"/>
- android:radius="5dp" />
- android:left="10dp"
- android:top="10dp"
- android:right="10dp"
- android:bottom="10dp" />
- android:radius="5dp" />
- android:left="10dp"
- android:top="10dp"
- android:right="10dp"
- android:bottom="10dp" />
關(guān)于button_selector.xml中shape的使用有疑問的可以看我上次的文章:Android中shape的使用。
【編輯推薦】
Android ListView詳解
Android開發(fā)中插入新的Activity
在Android應(yīng)用程序中使用Internet數(shù)據(jù)
分享文章:Android中focusable屬性的妙用之底層按鈕的實現(xiàn)
URL網(wǎng)址:http://m.fisionsoft.com.cn/article/dheohhd.html


咨詢
建站咨詢
