我怎样才能在android上实现一个装满水的瓶子?

Sme*_*eff -1 android

我想制作一个应用程序,您可以在其中添加每天喝多少盎司的水,并显示水瓶装满的动画。我将如何解决这个问题?

Sat*_*jit 5

您可以使用帧动画轻松制作。

玻璃填充

创建动画列表。像这样

 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 的背景,然后调用动画。