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

Android中focusable屬性的妙用之底層按鈕的實現

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

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

注意圖中我畫的箭頭,當時鼠標點擊的黑色圈圈的位置,然后按鈕出現了按下的效果(黃色的描邊)

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

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

具體代碼如下:

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.             <!-- 實心,即填充 -->   
  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.             <!-- 實心,即填充 -->   
  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> 

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

【編輯推薦】

Android ListView詳解

Android開發中插入新的Activity

在Android應用程序中使用Internet數據

責任編輯:zhaolei 來源: 博客園
相關推薦

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工作流調度器

2010-09-03 10:18:06

CSSdisplay:inl

2022-12-26 09:27:48

Java底層monitor

2010-07-15 14:23:42

SQL Server數

2024-05-28 12:25:33

Pythonglobals?函數

2011-06-01 14:20:37

Android

2011-08-12 11:31:46

iPhoneUIView動畫

2024-12-19 09:00:00

字典視圖對象Python

2009-06-03 09:01:41

微軟Windows 7操作系統

2021-06-09 11:41:10

RateLimiterJava代碼

2021-01-08 08:34:09

Synchronize線程開發技術

2021-10-20 07:36:03

Python構造方法

2023-07-11 08:00:00

2013-04-16 14:42:38

云計算智能手機移動通信網絡
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 99亚洲精品 | 久久激情网 | 欧美一级在线 | 国产综合在线视频 | 自拍偷拍中文字幕 | 国产一区二区三区四区区 | 久久精品视频在线观看 | www.国产一区| 亚洲久久一区 | 久久精品 | wwww.xxxx免费 | 久久久久久久国产精品视频 | 欧洲视频一区二区 | 天堂一区二区三区四区 | 免费一级黄色 | 日韩a v在线免费观看 | 亚洲 一区 | 国产一区二区三区久久久久久久久 | 亚洲精品视频一区 | 精品国产乱码久久久久久丨区2区 | 国产一区二区黑人欧美xxxx | 国产一区二区三区四区三区四 | 国产精品久久久久久久久久久久久 | 国产成视频在线观看 | 99久久夜色精品国产亚洲96 | 精品欧美乱码久久久久久1区2区 | 中文字幕在线国产 | 国产精品揄拍一区二区久久国内亚洲精 | 久久久久久综合 | 伊人伊人 | 亚洲视频免费在线观看 | 亚洲精品欧美 | 国产一区 | 欧美久久免费观看 | 久久中文视频 | 欧美激情一区二区三区 | 国产精品国产精品国产专区不片 | 欧美性tv| 国产精品99久久久久久www | 国产成人综合网 | 在线看av的网址 |