使用AnimationDrawable和XML形状加载点

时间:2016-10-27 12:10:32

标签: android xml animation

我想让动画看起来像https://www.bensherman.co.uk/img/skin/loading.gif

使用xml形状文件。目前我已经: EmptyDot XML

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" android:useLevel="true"
    android:dither="true">

    <size android:height="12dip" android:width="12dip"/>

    <solid android:color="#f214"/>
</shape>

BiggerdotXML

<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval" android:useLevel="true"
        android:dither="true">

        <size android:height="15dip" android:width="15dip"/>

        <solid android:color="#f214"/>
    </shape>

动画列表XML

 <animation-list
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:oneshot="false" >

         <item android:drawable="@drawable/EmptyDot" android:duration="300" />

         <item android:drawable="@drawable/BiggerDot" android:duration="300"
             />

    </animation-list>

MainActivity

ImageView loadingDots = (ImageView) findViewById(R.id.loadIngDots);
        final AnimationDrawable myAnimationDrawable
                = (AnimationDrawable)loadingDots.getDrawable();

        loadingDots.post(
                new Runnable(){

                    @Override
                    public void run() {
                        myAnimationDrawable.start();
                    }
                });

如何存储可以包含多个可以在动画列表中使用的Dot XML文件的XML视图?例如,在我的动画列表XML中,我希望获得类似的东西:

第1项BiggerdotXML,EmptydotXML,EmptydotXML,EmptydotXML
第2项EmptydotXML,BiggerdotXML,EmptydotXML,EmptydotXML
第3项EmptydotXML,EmptydotXML,BiggerdotXML,EmptydotXML
第4项EmptydotXML,EmptydotXML,EmptydotXML,BiggerdotXML

0 个答案:

没有答案