android 實現ImageView按壓效果和解決背景圖片拉申問題

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   color   使用   sp   檔案   

建立一個.XML檔案,名為:image_tab_bg.xml

1 <?xml version="1.0" encoding="utf-8"?>2 <selector3   xmlns:android="http://schemas.android.com/apk/res/android">4     <item android:state_pressed="true" android:drawable="@drawable/image_press" />//壓下片5     <item android:state_enabled="true" android:drawable="@drawable/image" />    //未按壓作圖片6     7  </selector>

然後你要實現的圖片ImageView的src設為:@drawable/image_tab_bg即可

注意:不要設為ImageView的Background屬性中;這樣圖片會被拉申

 

ImageView中XML屬性src和background的區別:

background會根據ImageView組件給定的長寬進行展開,而src就存放的是原圖的大小,不會進行展開。src是圖片內容(前景),bg是背景,可以同時使用。

此外:scaleType只對src起作用;bg可設定透明度,比如在ImageButton中就可以用android:scaleType控製圖片的縮放方式

 

android 實現ImageView按壓效果和解決背景圖片拉申問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.