Create a Activity class with same package name and copy these code.(If you can make your own package change the class according to it)
package graphics.example;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;
public class Graphics extends Activity {
AnimationDrawable logoAnimation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView logoImage=(ImageView) findViewById(R.id.iv1);
logoImage.setBackgroundResource(R.drawable.logo_animation);
logoAnimation=(AnimationDrawable) logoImage.getBackground();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
logoAnimation.start();
return true;
}
else return super.onTouchEvent(event);
}
}
Copy the code below in main.xml file in res/layout folder
<?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="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<ImageView
android:id="@+id/iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Create a xml file in drawable folder and put sequence of image in this folder you want animate
<?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/frame0a" android:duration="2000"/>
<item android:drawable="@drawable/frame1a" android:duration="100"/>
<item android:drawable="@drawable/frame2a" android:duration="100"/>
<item android:drawable="@drawable/frame3a" android:duration="100"/>
<item android:drawable="@drawable/frame4a" android:duration="100"/>
<item android:drawable="@drawable/frame5a" android:duration="100"/>
<item android:drawable="@drawable/frame6a" android:duration="100"/>
<item android:drawable="@drawable/frame7a" android:duration="100"/>
<item android:drawable="@drawable/frame8a" android:duration="100"/>
<item android:drawable="@drawable/frame9a" android:duration="2000"/>
</animation-list>
Screen shot of the output
source file can be downloaded from below link
click here
good start..
ReplyDeletethanks!!
Delete