帮助框架动画Android

Cra*_*aig 2 animation android

我一直试图让它使用这个线程,但似乎无法让它工作.

逐帧动画

我试图让屏幕在两个布局之间交替,我尝试了许多不同的东西,从状态列表drawables,形状drawables,甚至flipViews(flipViews不起作用,因为你不能改变背景,只是前景).

现在我得到一个空指针.如果你想指出我不能在动画中使用布局,那么请这样做,因为它可能是问题,但我不能确定.任何达到我最终目标的解决方案都表示赞赏.

我的Oncreate包含以下内容(减去标准内容)

ImageView mainimage = (ImageView) findViewById(R.id.main);
     mainimage.setBackgroundResource(R.anim.blink);
     AnimationDrawable blinkAnimation = (AnimationDrawable) mainimage.getBackground();
     blinkAnimation.start();
Run Code Online (Sandbox Code Playgroud)

我的动画文件包含:(减去utf的东西)

<

animation-list xmlns:android="http://schemas.android.com/apk/res/android"
        android:oneshot="false">
        <item android:drawable="@drawable/royalblue" android:duration="200" />
        <item android:drawable="@drawable/blank" android:duration="200" />
    </animation-list>
Run Code Online (Sandbox Code Playgroud)

Image视图中的Main只是这个空白的xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我放置在drawable文件夹中的布局,因为我希望它是动画中的一个框架.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/blinkBlue"
    android:background="@color/royalBlue"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    >

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我放在drawable文件夹中的另一个布局,因为我希望它是动画中的一个框架.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/blinkBlack"
        android:background="@color/black"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        >

    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

obr*_*ien 5

我知道这是很晚的反应,但对于其他正面临同样问题的人来说,我的解决方案是:

AnimationDrawable drawable = (AnimationDrawable)getResources().getDrawable(R.anim.amin_list);
ImageView im = (ImageView) findViewById(R.id.image);
im .setBackgroundDrawable(drawable);
im .post(drawable);
Run Code Online (Sandbox Code Playgroud)

其中amin_list是:

<animation-list  android:oneshot="false" 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/progress_1" android:duration="150" />
    <item android:drawable="@drawable/progress_2" android:duration="150" />
    <item android:drawable="@drawable/progress_3" android:duration="150" />
    <item android:drawable="@drawable/progress_4" android:duration="150" />
 </animation-list> 
Run Code Online (Sandbox Code Playgroud)