欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android ImageView的selector效果實例詳解

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

Android ImageView的selector效果實例詳解

在平時開發(fā)中如Button我們給它加上selector分別呈現(xiàn)pressed以及normal效果能給我們的用戶體驗上大大增色不少,可是我們當我們是用ImageView來”當作”一個一個”Button”的時候發(fā)現(xiàn)直接設置selector卻不起作用,當然此時我們的應用就表現(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設置該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設置backgroundResource,然后給src設置我們設置好的selector,在視覺上我們的selector是顯示在ImageView的上方,當然我們點擊ImageView的時候就是觸發(fā)selector,這個時候就會有按下的效果了。

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

相關文章

最新評論