Repeat the animated background

1

I made an application with an animated background, here is the code:

Main layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Main" >
...

The animation list:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/matrix_39" android:duration="100" />
<item android:drawable="@drawable/matrix_38" android:duration="100" />
<item android:drawable="@drawable/matrix_37" android:duration="100" />
<item android:drawable="@drawable/matrix_36" android:duration="100" />
...

The java implementation:

public class Main extends Activity {
    LinearLayout bck;
    AnimationDrawable ad;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bck = (LinearLayout) findViewById(R.id.background);
        bck.setBackgroundResource(R.drawable.progress_animation);
        ad = (AnimationDrawable) bck.getBackground();
        ad.start();
}

Well, it works great as well as animated full-screen backdrop, but I would like to repeat the animated background image. Is there a way?

    
asked by anonymous 05.02.2014 / 20:04

1 answer

1

If I understood your question well what you have to do is to add ad.setOneShot(false) before doing ad.start() .

public class Main extends Activity {
    LinearLayout bck;
    AnimationDrawable ad;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bck = (LinearLayout) findViewById(R.id.background);
        bck.setBackgroundResource(R.drawable.progress_animation);
        ad = (AnimationDrawable) bck.getBackground();
        ad.setOneShot(false);
        ad.start();
}  

Another thing I read about documentation is that start() should not be done in the onCreate method of Activity but in onWindowFocusChanged

    
05.02.2014 / 20:30