tried to do frame by frame animation nothing appears

All your problems with Audio, Video and Images.

tried to do frame by frame animation nothing appears

Postby guyenanddev » Tue Nov 23, 2010 5:09 am

Hi guys, I have tried to setup the frame-by-frame animation but once the activity starts, nothing can be seen on the screen. Could someone take a look?
Here is my setup:

in res\drawable\-hdpi\front_light_animation.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/front_light1" android:duration="50"/>
<item android:drawable="@drawable/front_light2" android:duration="50"/>
</animation-list>

In layout\front_light.xml where imageTag is for graphic files show:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="front Head Light animation"
android:textColor="@color/yellow"
android:textSize="@dimen/introSize"/>

<ImageView
android:id="@+id/animationImage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="..."
android:textColor="@color/yellow"
android:textSize="@dimen/introSize"/>

</LinearLayout>

Here is the java code in the activity file to do the animation:

public class frontLightActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.front_light);
animate();
}

private void animate()
{
ImageView view = (ImageView)findViewById(R.id.animationImage);
view.setVisibility(ImageView.VISIBLE);
view.setBackgroundResource(R.drawable.front_light_animation);
AnimationDrawable frameAnimation = (AnimationDrawable)view.getBackground();
frameAnimation.start();
}
}
guyenanddev
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Nov 17, 2010 12:00 am

Top

Re: tried to do frame by frame animation nothing appears

Postby guyenanddev » Wed Nov 24, 2010 5:47 am

someone please help...
guyenanddev
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Nov 17, 2010 12:00 am

Re: tried to do frame by frame animation nothing appears

Postby srd.pl » Thu Nov 25, 2010 6:02 pm

hey I recently also had problems with animation. What I think is that the animation doesn't start from the onCreate method (some sort of bug I guess) there is some more info on the net - just ask google. What I did to start the animation at the opening of the activity was to put inside the onWindowsFocusChange method. That should help.

PS: if you will run into out of memory problems (which I had), skip the xml file and load the animation manually hard-coded from bitmaps. then you can release the bitmaps and avoid memory leaks.
srd.pl
Junior Developer
Junior Developer
 
Posts: 22
Joined: Wed Jun 02, 2010 12:20 pm

Re: tried to do frame by frame animation nothing appears

Postby guyenanddev » Sat Nov 27, 2010 10:31 pm

thanks man i am gonna try it now and see what happens.
guyenanddev
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Nov 17, 2010 12:00 am

Re: tried to do frame by frame animation nothing appears

Postby guyenanddev » Sun Nov 28, 2010 10:15 am

Okay, I changed the code so that the animation does not start at onCreate() method, instead I modified it so that Button is created during onStart and defined onClickListener which does the actual animation. Actually I made it exactly same as my tutorial I am studying from does stay.
Here is the code excerpt. Here button is created and fetched from xml using id startFAButton and assigned onClickListener which in turn calls the

public class frontLightActivity extends Activity
{
Button b;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.front_light);
this.setupButton();
//animate();
}


// setup Button for starting the animation.

private void setupButton()
{
b = (Button)findViewById(R.id.startFAButtonId); // retrieve button by ID.
b.setOnClickListener
(
new Button.OnClickListener()
{
public void onClick(View v)
{
b.setText("onClick");
parentButtonClicked(v);
}
}
);
}

private void parentButtonClicked(View v)
{
b.setText("parentButtonClicked");
animate();
}

private void animate()
{
ImageView view = (ImageView)findViewById(R.id.animationImage);
view.setVisibility(ImageView.VISIBLE);
view.setBackgroundResource(R.drawable.front_light_animation);
AnimationDrawable frameAnimation = (AnimationDrawable)view.getBackground();

if(frameAnimation.isRunning())
{
frameAnimation.stop();
}
else
{
frameAnimation.stop();
frameAnimation.start();
}
}
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="front Head Light animation"
android:textColor="@color/yellow"
android:textSize="@dimen/introSize"/>

<Button
android:id="@+id/startFAButtonId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Start Animation"
/>

<ImageView
android:id="@+id/animationImage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="..."
android:textColor="@color/yellow"
android:textSize="@dimen/introSize"/>

</LinearLayout>
guyenanddev
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Nov 17, 2010 12:00 am

Re: tried to do frame by frame animation nothing appears

Postby srd.pl » Mon Nov 29, 2010 1:00 pm

But does it work now? If it doesn't I would skip the if with isAnimating() or use the debugger to check if the start() function is called. Imo the code looks fine, though I usually make buttonlisteners as a activity method. If it is still stuck I don't know how else to help - as I wrote I only began playing with animation.
srd.pl
Junior Developer
Junior Developer
 
Posts: 22
Joined: Wed Jun 02, 2010 12:20 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 12 guests