我们经常的点击按钮 或者文本会突然放大 其实使用的不是什么新技术,在你需要放大的控件下面添加一个属性就好
在res文件下创建一个animate_scale.xml文件,你可以选择创建在xml文件下或者创建在animator文件下,都可以使用
下面是代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 按下状态;将 x 和 y 大小增加到 300% -->
<item android:state_pressed="true">
<set>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleX"
android:valueTo="3.5"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleY"
android:valueTo="3.5"
android:valueType="floatType" />
</set>
</item>
<!-- 默认的非按下状态;将 x 和 y 大小设置为 100% -->
<item android:state_pressed="false">
<set>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleX"
android:valueTo="1"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleY"
android:valueTo="1"
android:valueType="floatType" />
</set>
</item>
</selector>
在你需要放大的控件下面添加一个属性
android:stateListAnimator="@xml/animate_scale"
然后运行就OK了,只要被点击就会被放大
通过在Android项目中创建animate_scale.xml资源文件,利用Selector和ObjectAnimator实现按钮或文本被点击时的缩放动画效果。点击时控件将放大到3.5倍,松开后恢复到原始大小。只需在目标控件上添加android:stateListAnimator属性引用该动画即可。
775

被折叠的 条评论
为什么被折叠?



