【发布时间】:2020-01-04 08:25:26
【问题描述】:
我正在关注here给出的文章
我正在尝试创建一个“喜欢”按钮动画并且需要帮助,因为我的动画师似乎没有做任何事情
我已经创建了所需的动画文件,创建了 stateListDrawable 文件并将其设置为 CheckBox 的背景 animator 文件使用一组 objectAnimator 标签,它们为 scaleX、scaleY 和 translationZ 属性设置动画。
这是我的布局文件“activity_main.xml”
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@android:color/white"
android:layout_height="match_parent"
tools:context=".MainActivity">
<CheckBox
android:id="@+id/checkbox"
android:button="@null"
android:checked="false"
android:background="@drawable/like_icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:stateListAnimator="@animator/scale2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是 stateListDrawable "like_icon.xml"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_thumb_up_red_24dp"
android:state_checked="true" />
<item android:drawable="@drawable/ic_thumb_up_black_24dp" />
</selector>
这是我的动画师,名为“scale.xml”。正确放置在“res/animator/”文件夹中
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="@android:integer/config_longAnimTime"
android:propertyName="scaleX"
android:valueTo="1.525"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_longAnimTime"
android:propertyName="scaleY"
android:valueTo="1.525"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_longAnimTime"
android:propertyName="translationZ"
android:valueTo="4dp"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_longAnimTime"
android:propertyName="scaleX"
android:valueTo="1.0"
android:startOffset="@android:integer/config_longAnimTime"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_longAnimTime"
android:propertyName="scaleY"
android:startOffset="@android:integer/config_longAnimTime"
android:valueTo="1.0"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_longAnimTime"
android:propertyName="translationZ"
android:startOffset="@android:integer/config_longAnimTime"
android:valueTo="0dp"
android:valueType="floatType" />
</set>
【问题讨论】:
标签: android android-layout animation checkbox objectanimator