亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android ImageView的selector效果實(shí)例詳解

 更新時(shí)間:2017年07月15日 11:51:08   投稿:lqh  
這篇文章主要介紹了Android ImageView的selector效果實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下

Android ImageView的selector效果實(shí)例詳解

在平時(shí)開發(fā)中如Button我們給它加上selector分別呈現(xiàn)pressed以及normal效果能給我們的用戶體驗(yàn)上大大增色不少,可是我們當(dāng)我們是用ImageView來”當(dāng)作”一個一個”Button”的時(shí)候發(fā)現(xiàn)直接設(shè)置selector卻不起作用,當(dāng)然此時(shí)我們的應(yīng)用就表現(xiàn)的暗淡了。那我們就只能找到方法來解決這種情況。

首先定義一個selector文件:

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
  <item android:state_pressed="true">
    <shape android:shape="rectangle">
      <corners android:radius="5dp" />
      <solid android:color="#50000000"/>
    </shape>
  </item>

  <item >
    <shape android:shape="rectangle">
      <corners android:radius="5dp" />
      <solid android:color="#00000000"/>
    </shape>
  </item>

</selector>

第二步,給ImageView的src設(shè)置該selector。

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:contentDescription="@null"
    android:scaleType="centerCrop"
    android:src="@drawable/share_image_selector" />

然后我們的ImageVIew上要呈現(xiàn)的圖片資源就是用

mImageView.setBackgroundResource(R.drawable.icon);

也就是說我們是給imageview設(shè)置backgroundResource,然后給src設(shè)置我們設(shè)置好的selector,在視覺上我們的selector是顯示在ImageView的上方,當(dāng)然我們點(diǎn)擊ImageView的時(shí)候就是觸發(fā)selector,這個時(shí)候就會有按下的效果了。

以上就是Android ImageView的自定義開發(fā),對于Android很多東西都需要重寫,不美觀肯定不是好的APP,本站還有很多關(guān)于Android開發(fā)的文章,請大家參閱,謝謝大家對本站的支持!

相關(guān)文章

最新評論