Simple ImageView color animation

↘锁芯ラ 提交于 2019-12-02 02:16:07
NSimon

How about having 2 images of the bottle? One (on foreground) would be an empty bottle with transparency The (on background) second one would be the "shape of the liquid"

when your activity starts, get the background one and animate it like posted on this topic : https://stackoverflow.com/a/12127985/4232337

Hope this helps!

You can do this by using a custom ProgressBar. Even more simpler

<ProgressBar
            android:id="@+id/progressbar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginBottom="2dp"
            android:layout_marginTop="2dp"
            android:indeterminateOnly="false"
            android:max="100"
            android:progress="30"
            android:progressDrawable="@drawable/progress_bar_clip" >
        </ProgressBar>

progress_bar_clip.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/background">
        <clip
            android:clipOrientation="vertical"
            android:drawable="@drawable/ic_launcher"
            android:gravity="bottom" />
    </item>
    <item android:id="@android:id/progress">
        <clip
            android:clipOrientation="vertical"
            android:gravity="bottom" >
            <bitmap android:src="@drawable/ic_launcher" >
            </bitmap>
        </clip>
    </item>

</layer-list>

You don't have do load any animations. Just use a handler and increment the progress bar by 1.

final ProgressBar bar = (ProgressBar) findViewById(R.id.progressbar);

        final Handler handler = new Handler();
        runnable = new Runnable() {

            @Override
            public void run() {
                if(bar.getProgress() != 100) {
                    bar.incrementProgressBy(1);
                    handler.postDelayed(runnable, 500);
                }
            }
        };;

        handler.post(runnable);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!