您可以使用帧动画轻松制作。
创建动画列表。像这样
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>
Run Code Online (Sandbox Code Playgroud)
然后使用动画列表的背景在您的布局中添加 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" />
Run Code Online (Sandbox Code Playgroud)
然后在你的活动 onClick of something 或 onstart 调用这个
((AnimationDrawable) mGlassView1startkground()).start();
Run Code Online (Sandbox Code Playgroud)
您甚至可以以编程方式将 animationlistfilling.xml 设置为 imageview 的背景,然后调用动画。
| 归档时间: |
|
| 查看次数: |
3362 次 |
| 最近记录: |