首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在android上实现水瓶装满?

如何在android上实现水瓶装满?
EN

Stack Overflow用户
提问于 2015-10-01 22:51:04
回答 1查看 3.5K关注 0票数 -1

我想做一个应用程序,你可以添加你每天喝多少盎司的水,并显示一个水瓶装满的动画。我如何才能做到这一点?

EN

回答 1

Stack Overflow用户

发布于 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设置为图像视图的背景,然后调用动画。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32890592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档