0

I want to create a background that covers the whole screen of my Activity. Just like:

 android:background="@drawable/background"

But I want this background to be animated (60 frames), looping and target as many device resolutions as possible.

I tried to do a drawble .jpg sequence, but the problem is that I use 1920x1080, and the logcat while trying to test it on the emulator, the application crashes, and LogCat gives me en error saying, not enough memory

Then I tried to import a video of my sequence and set it to play on the background. But I don't know where to put the video in my res folder and call it from there with SetVideoPath(), in order to play it.

What is the best approach for an animated background, that covers multiple devices with different resolutions?

@Arun C Thomas

I still get an error in logcat,

OutOfMemoryError

my code is this:

package combiolab.biolab;


import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Bundle;
import android.view.WindowManager;

public class MainActivity extends Activity {

    private Renderer graphicsRenderer;

    //public static String gl;
    AnimationDrawable anim;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
       getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

       GLSurfaceView myGLSurfaceView = (GLSurfaceView) findViewById(R.id.gl);
       myGLSurfaceView.setEGLConfigChooser(true);         
       myGLSurfaceView.setRenderer(graphicsRenderer);
    }



    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        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=".MainActivity" >


         <android.opengl.GLSurfaceView 
            android:id="@+id/gl" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent">
        </android.opengl.GLSurfaceView>



    </RelativeLayout>
user2186852
  • 381
  • 1
  • 4
  • 11
  • scale down the bitmap and then display the same. http://developer.android.com/training/displaying-bitmaps/load-bitmap.html – Raghunandan Apr 17 '13 at 08:32
  • you can place the video in the assets folder of the project. Then you can use AssetManager to access the file. – Pavan Apr 17 '13 at 08:49

1 Answers1

1

You need to create an OpenGL view, then add it like

 <android.opengl.GLSurfaceView 
        android:id="@+id/gl" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">
    </android.opengl.GLSurfaceView>

In onCreate() implement Renderer like

GLSurfaceView myGLSurfaceView = (GLSurfaceView) findViewById(R.id.gl);
    myGLSurfaceView.setEGLConfigChooser(true);         
    myGLSurfaceView.setRenderer(graphicsRenderer);
Arun C
  • 9,035
  • 2
  • 28
  • 42