【发布时间】:2019-08-29 13:51:41
【问题描述】:
我想编写一个动画来翻译视图并同时缩放它。这是一个简单的动画,但运行时,它不能正常工作。它以曲线而不是直线运行。 视图的布局 xml 和 anim.xml 在下面
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_height="match_parent"
tools:context=".Main2Activity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="clickBtn"
android:text="startAnim"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>
// anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="8000"
android:shareInterpolator="true">
<translate
android:fromYDelta="0%p"
android:toYDelta="-100%p" />
<alpha
android:fromAlpha="1"
android:toAlpha="0" />
<scale
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="0.2"
android:toYScale="0.2" />
【问题讨论】: