0

I try to use the AnimationDrawable to display a Loading Animation. I make the loading "Screen" Visible by set its Visibility to VISIBLE.

I know that a AnimationDrawable should be started AFTER the screen is set and i used the solution from Google Developers with onWindowFocusChanged:

    @Override public void onWindowFocusChanged(boolean hasFocus) {
    // TODO Auto-generated method stub
        super.onWindowFocusChanged(hasFocus);ImageView img = (ImageView)findViewById(R.id.animationView);
    img.setBackgroundResource(R.drawable.animation_position);

    AnimationDrawable frameAnimation = (AnimationDrawable)img.getBackground();

    if (hasFocus){
            //normal Screen
    RelativeLayout listView = (RelativeLayout)findViewById(R.id.listAnzeige);
    listView.setVisibility(View.GONE);

    //Loading Screen
    RelativeLayout ladeScreen = (RelativeLayout)findViewById(R.id.Position);
    ladeScreen.setVisibility(View.VISIBLE);


    frameAnimation.start();

My XML File:

<?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/f1" android:duration="100" />
<item android:drawable="@drawable/f2" android:duration="100" />
<item android:drawable="@drawable/f3" android:duration="100" />
<item android:drawable="@drawable/f4" android:duration="100" />
<item android:drawable="@drawable/f5" android:duration="100" />
<item android:drawable="@drawable/f6" android:duration="100" /></animation-list>    

The animation doesn't start. I think the problem is the Visibility but i am not sure. Thanks for help.

user2332887
  • 1
  • 1
  • 2

0 Answers0