开发者

Help with Frame Animation Android

I have been trying to get it to work using this thread but can't seem to get it to work.

Frame-by-frame animations

I am trying to get the screen to alternate between two layouts and I have tried lots of different things from state list drawables, to shape drawables, and even flipViews(flipViews didn't work because you cannot change the background, just the foreground).

Right now I am getting a null pointer. If you would like to point out that I can not use a layout in an animation then please do so as it's probably the problem but I can't be sure. Any solution to reach my开发者_高级运维 end goal is appreciated.

My Oncreate contains the following(minus the standard stuff)

ImageView mainimage = (ImageView) findViewById(R.id.main);
     mainimage.setBackgroundResource(R.anim.blink);
     AnimationDrawable blinkAnimation = (AnimationDrawable) mainimage.getBackground();
     blinkAnimation.start();

My Animation file contains this:(minus the utf stuff)

<

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>

The Main in the Image view is just this blank xml file

<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>

This is the layout I have placed in the drawable folder because I want it to be a frame in the animation.

<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>

This is the other layout I have placed in the drawable folder because I want it to be a frame in the animation.

<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>


I know that this is quite late response but for the others who are facing the same issue here is my solution:

AnimationDrawable drawable = (AnimationDrawable)getResources().getDrawable(R.anim.amin_list);
ImageView im = (ImageView) findViewById(R.id.image);
im .setBackgroundDrawable(drawable);
im .post(drawable);

Where amin_list is:

<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> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜