Use of Android development animations (iii)
This blog post focuses on the effects of animations in Android development to cycle through animations:
Mainactivity.java:
Package com.example.animationtest3;
Import Android.os.Bundle;
Import android.app.Activity;
Import android.graphics.drawable.AnimationDrawable;
Import Android.view.Menu;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.ImageView;
/*
* Frame by Frame Animation
* */
public class Mainactivity extends Activity {
Private ImageView ImageView = null;
Private Button Scalebutton = null;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
ImageView = (ImageView) Findviewbyid (r.id.myimage);
Scalebutton = (Button) Findviewbyid (R.id.scalebutton);
Scalebutton.setonclicklistener (New Setscalelistener ());
}
Animation Zoom Effect Listener
Class Setscalelistener implements onclicklistener{
@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
Can be used to modify the background image
Imageview.setbackgroundresource (r.drawable.img_list);
Animationdrawable animationdrawable = (animationdrawable) imageview.getbackground ();
Animationdrawable.start ();
}
}
@Override
public boolean Oncreateoptionsmenu (Menu menu) {
Inflate the menu; This adds items to the action bar if it is present.
Getmenuinflater (). Inflate (R.menu.main, menu);
return true;
}
}
Main layout file Main.xml:
<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: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 ">
<textview
Android:id= "@+id/mytext"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "@string/hello_world"/>
<linearlayout
Android:id= "@+id/imglayout"
android:layout_below= "@id/mytext"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
Android:padding= "55DP"
>
<imageview
Android:id= "@+id/myimage"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
/>
</LinearLayout>
<button
Android:id= "@+id/scalebutton"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:layout_below= "@id/imglayout"
android:text= "Start Animation"
/>
</RelativeLayout>
new XML file under the Drawable folder :
<?xml version= "1.0" encoding= "Utf-8"?>
<animation-list xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:drawable= "@drawable/list1" android:duration= "/>"
<item android:drawable= "@drawable/list2" android:duration= "/>"
<item android:drawable= "@drawable/list3" android:duration= "/>"
<item android:drawable= "@drawable/list4" android:duration= "/>"
</animation-list>
Use of Android development animations (iii)