我想做一个应用程序,你可以添加你每天喝多少盎司的水,并显示一个水瓶装满的动画。我如何才能做到这一点?
发布于 2018-08-13 20:36:56
您可以使用帧动画轻松完成此操作。
创建动画列表。像这样
filling_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item
android:duration="50"
android:drawable="@drawable/glass1"/>
<item
android:duration="50"
android:drawable="@drawable/glass2"/>
<item
android:duration="50"
android:drawable="@drawable/glass3"/>
<item
android:duration="50"
android:drawable="@drawable/glass4"/>
</animation-list>
然后使用ImageView列表的背景在布局中添加动画。
<ImageView
android:id="@+id/image_view_glass1"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_marginLeft="20dp"
android:background="@drawable/filling_animation"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@id/image_view_glass2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
然后在你的activity onClick of something或onstart中调用这个
((AnimationDrawable) mGlassView1startkground()).start();
您甚至可以通过编程将animationlistfilling.xml设置为图像视图的背景,然后调用动画。
https://stackoverflow.com/questions/32890592
复制相似问题