Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using android animation-list

I'm having a little trouble getting an animated loading spinner to work for a splash page. Nothing shows up when I try to run the following code. Any suggestions? It seems that quite a few people have issues with this on google but I do not understand why mine is failing to work. Thanks!

animationloader.xml

<?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/loadingspinner1" android:duration="200" />
<item android:drawable="@drawable/loadingspinner2" android:duration="200" />
<item android:drawable="@drawable/loadingspinner3" android:duration="200" />
<item android:drawable="@drawable/loadingspinner4" android:duration="200" />
<item android:drawable="@drawable/loadingspinner5" android:duration="200" />
<item android:drawable="@drawable/loadingspinner6" android:duration="200" />
<item android:drawable="@drawable/loadingspinner7" android:duration="200" />
<item android:drawable="@drawable/loadingspinner8" android:duration="200" />
<item android:drawable="@drawable/loadingspinner9" android:duration="200" />
<item android:drawable="@drawable/loadingspinner01" android:duration="200" />
<item android:drawable="@drawable/loadingspinner11" android:duration="200" />
<item android:drawable="@drawable/loadingspinner12" android:duration="200" />
</animation-list>

SplashScreen.java

package com.secure.inmatecanteen;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;

public class SplashScreen extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splashscreen);

    //Beginning the loading animation as we attempt to verify registration with SIP
    ImageView ivLoader = (ImageView) findViewById(R.id.IVloadinganimation);
    ivLoader.setBackgroundResource(R.anim.animationloader);


    AnimationDrawable frameAnimation = (AnimationDrawable) ivLoader.getBackground();
    frameAnimation.start();
}
}

splashscreen.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="@android:color/white" >

 <ImageView
android:id="@+id/iclogo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/iclogo"
android:adjustViewBounds="true"
/>

 <ImageView
android:id="@+id/IVloadinganimation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
/>

    </LinearLayout>
like image 475
tier1 Avatar asked Jan 04 '12 02:01

tier1


People also ask

How do you animate on Android?

Navigate to the app > res > Right-Click on res >> New >> Directory >> Name your directory as “anim”. Inside this directory, we will create our animations. For creating a new anim right click on the anim directory >> Animation Resource file and give the name to your file.

How many types of animation are there in Android?

There are three animation systems that work differently for different cases but the most important are Property animations. Property animations allow us to animate any property of any object from one value to another over a specified duration. These can be applied to anything within the Android application.

Can we do animation in Android?

On Android 5.0 (API level 21) and higher, you can also create animations that transition between your activities. This is based on the same transition framework described above to animate layout changes, but it allows you to create animations between layouts in separate activities.

What are two different types of view animations?

There are two types of animations that you can do with the view animation framework: Tween animation: Creates an animation by performing a series of transformations on a single image with an Animation. Frame animation: or creates an animation by showing a sequence of images in order with an AnimationDrawable .


1 Answers

Solved my own problem, You cannot start animations in the oncreate. It has to be in an onclick listener or inside a runnable.

like image 152
tier1 Avatar answered Oct 06 '22 17:10

tier1