成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Android中focusable屬性的妙用之底層按鈕的實(shí)現(xiàn)

移動開發(fā) Android
最近比較熱衷于Android開發(fā)這方面,關(guān)注到了許多像下面這樣對例子,分享一下。Focusable 是 Microsoft .NET 屬性訪問器,它實(shí)際上是一個依賴項(xiàng)屬性。 這一特定依賴項(xiàng)屬性非常普遍地在派生元素類(尤其是控件)中以不同方式設(shè)置其原本的“默認(rèn)”值。 這種情況通常以兩種方式發(fā)生

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

注意圖中我畫的箭頭,當(dāng)時(shí)鼠標(biāo)點(diǎn)擊的黑色圈圈的位置,然后按鈕出現(xiàn)了按下的效果(黃色的描邊)

剛開始看到這種效果很是好奇,不知道是怎么實(shí)現(xiàn)的,后來仔細(xì)一想,應(yīng)該是整個啤酒罐是一張圖片(ImageView),該圖片是布局在三個按鈕之上,然后就是最關(guān)鍵的地方,把圖片設(shè)置為不可獲取焦點(diǎn),也就是android:focusable="false" ,就這樣簡單的一行,就可以搞定了!

為了驗(yàn)證我的想法,我建了一個工程來做測試,效果如下圖所示:

具體代碼如下:

main.xml:

  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"   
  3.     android:layout_width="fill_parent"   
  4.     android:layout_height="fill_parent"   
  5.     >   
  6.     <LinearLayout   
  7.         android:layout_width="match_parent"   
  8.         android:layout_height="wrap_content"   
  9.         android:orientation="vertical" >   
  10.         <Button   
  11.             android:layout_width="match_parent"   
  12.             android:layout_height="wrap_content"   
  13.             android:layout_margin="10dp"   
  14.             android:text="button1"   
  15.             android:background="@drawable/button_selector"   
  16.             />      
  17.         <Button   
  18.             android:layout_width="match_parent"   
  19.             android:layout_height="wrap_content"   
  20.             android:layout_margin="10dp"   
  21.             android:text="button2"   
  22.             android:background="@drawable/button_selector"   
  23.             />    
  24.         <Button   
  25.             android:layout_width="match_parent"   
  26.             android:layout_height="wrap_content"   
  27.             android:layout_margin="10dp"   
  28.             android:text="button3"   
  29.             android:background="@drawable/button_selector"   
  30.             />    
  31.     </LinearLayout>   
  32.     <ImageView   
  33.         android:layout_width="wrap_content"   
  34.         android:layout_height="wrap_content"   
  35.         android:src="@drawable/bg2"   
  36.         android:focusable="false"   
  37.         />   
  38. </RelativeLayout> 

button_selector.xml:

  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <selector   
  3.     xmlns:android="http://schemas.android.com/apk/res/android">   
  4.     <item android:state_pressed="true" >   
  5.         <shape>   
  6.             <!-- 實(shí)心,即填充 -->   
  7.             <solid android:color="#8470FF"/>   
  8.             <!-- 描邊 -->   
  9.             <stroke   
  10.                 android:width="2dp"   
  11.                 android:color="#FFFF00"/>   
  12.             <!-- 圓角 -->   
  13.             <corners   
  14.                 android:radius="5dp" />   
  15.             <padding   
  16.                 android:left="10dp"   
  17.                 android:top="10dp"   
  18.                 android:right="10dp"   
  19.                 android:bottom="10dp" />   
  20.         </shape>   
  21.     </item>   
  22.  
  23.     <item>         
  24.         <shape>   
  25.             <!-- 實(shí)心,即填充 -->   
  26.             <solid android:color="#8470FF"/>   
  27.             <corners   
  28.                 android:radius="5dp" />   
  29.             <padding   
  30.                 android:left="10dp"   
  31.                 android:top="10dp"   
  32.                 android:right="10dp"   
  33.                 android:bottom="10dp" />   
  34.         </shape>   
  35.     </item>   
  36. </selector> 

關(guān)于button_selector.xml中shape的使用有疑問的可以看我上次的文章:Android中shape的使用。

【編輯推薦】

Android ListView詳解

Android開發(fā)中插入新的Activity

在Android應(yīng)用程序中使用Internet數(shù)據(jù)

責(zé)任編輯:zhaolei 來源: 博客園
相關(guān)推薦

2010-09-10 15:16:51

CSSdisplay

2010-09-08 15:16:46

clearCSS

2010-09-09 16:54:05

CSSclear

2024-04-25 08:22:43

AndroidlargeHeap屬性

2010-08-30 16:02:06

CSSclear

2023-02-01 08:31:48

2016-03-03 15:11:42

Spark Strea工作流調(diào)度器

2022-12-26 09:27:48

Java底層monitor

2010-09-03 10:18:06

CSSdisplay:inl

2010-07-15 14:23:42

SQL Server數(shù)

2024-05-28 12:25:33

Pythonglobals?函數(shù)

2011-06-01 14:20:37

Android

2024-12-19 09:00:00

字典視圖對象Python

2011-08-12 11:31:46

iPhoneUIView動畫

2009-06-03 09:01:41

微軟Windows 7操作系統(tǒng)

2021-06-09 11:41:10

RateLimiterJava代碼

2021-01-08 08:34:09

Synchronize線程開發(fā)技術(shù)

2023-07-11 08:00:00

2021-10-20 07:36:03

Python構(gòu)造方法

2013-04-16 14:42:38

云計(jì)算智能手機(jī)移動通信網(wǎng)絡(luò)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 男人天堂av网站 | a级在线免费 | 亚洲国产精品成人综合久久久 | 久久se精品一区精品二区 | 成人伊人 | 欧美一区二| 国产中文字幕网 | 国产欧美日韩精品一区二区三区 | 青青久久久 | 91国内产香蕉 | 国产精品久久久久久久久久久久久 | 国产精品久久久久久一区二区三区 | 一区二区三区国产 | 欧美精品在线免费 | 国产精品一区二区在线播放 | 亚洲一区国产 | 欧美日韩电影免费观看 | 久久久精品视频免费 | 色天堂影院 | 黄色大片免费网站 | 人人玩人人干 | 天天综合干 | 久久国产成人午夜av影院武则天 | 亚洲精品短视频 | 国产精品久久久久一区二区三区 | 精品亚洲国产成av人片传媒 | 国产精品久久久久国产a级 欧美日韩国产免费 | 中文字幕在线欧美 | 亚洲一区二区视频 | 特一级黄色毛片 | 日韩毛片免费看 | www在线视频 | 97超碰人人 | 精品国产伦一区二区三区观看说明 | 午夜影晥| 国产日韩欧美一区二区 | 亚洲一区二区三区久久 | 中文字幕三区 | 91 在线| 欧美日韩国产精品激情在线播放 | 免费激情网站 |