anroid 点击图形缩小
发布时间:2020-12-16 06:10:52 所属栏目:百科 来源:网络整理
导读:这个功能是由selector + shape xml文件实现的 主要原理是把stroke的width变大把图形挤压变小,我用的是textview做测试,不知道其它控件是否生效,在此声明,以防参考者误用,也许还有更简单的方法,但我这里只是提供一种可以实现的方法,不喜勿喷,觉得有用
这个功能是由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就可以了 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |