Create frame animation in android

Hi, I am trying to set up a frame animation with a series of images as the background for my splash page in an Android application, I would do it, if possible, as a code to run at startup. I am writing code, but I get an error message that says "frame animation cannot be solved."

The java code that was implemented in my main action is as follows:

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView frameanimation = (ImageView) findViewById(R.id.frame_animation); AnimationDrawable frame_animation = (AnimationDrawable) frameanimation.getBackground(); frame_animation.setVisible(true, true); frame_animation.start(); } 

Then I have this code that implements the image representation in my XML layout file:

 <ImageView android:id="@+id/frame_animation" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:src="@drawable/frame_animation" /> 

and finally, my animation animation is saved as "frame_animation.xml" in my accessible folder.

 <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/homebckgrnda1" android:duration="200" /> <item android:drawable="@drawable/homebckgrnda2" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda3" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda4" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda5" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda6" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda7" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda8" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda9" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda10" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda11" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda12" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda13" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda14" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda15" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda16" android:duration="50" /> <item android:drawable="@drawable/homebckgrnda17" android:duration="50" /> </animation-list> 

Any help is much appreciated, I just canโ€™t understand what is going wrong.

thanks

+1
source share
1 answer

The source ImageView ( android:src ) and background ImageView ( android:background ) are two different things. You set the source in XML, but try to get the background image in the code ( frameanimation.getBackground() ).

+4
source

All Articles