anroid 點擊圖形縮小

這個功能是由selector + shape xml文件實現的 主要原理是把stroke的width變大把圖形擠壓變小,我用的是textview做測試,不知道其它控件是否生效,在此聲明,以防參考者誤用,也許還有更簡單的方法,但我這裏只是提供一種可以實現的方法,不喜勿噴,覺得有用的請贊。

首先你的寫一個點擊時候要顯示的樣子

定義爲 suoxiao.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    //顏色爲你的背景顏色
    <stroke android:width="4dp" android:color="#326475" />
    顏色爲控件原有顏色
    <solid android:color="#ff202a"/>
</shape>

在者你要設置沒有點擊時的顯示

shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#ff202a" />
</shape>

最關鍵的一步就是selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true"  android:drawable="@drawable/application_menu_first_suoxiao"></item>
    <item android:drawable="@drawable/application_menu_first_shape" android:state_pressed="false"></item>
</selector>

設置background爲selector就可以了

這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章