Xml Layouts:
Class File:
Animation Xml:
<?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/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ImageView>
<Button
android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start" >
</Button>
<Button
android:id="@+id/btnStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop" >
</Button>
</LinearLayout>
Class File:
public class AnimAppActivity extends Activity
{
Button btnStart,btnStop;
ImageView img;
AnimationDrawable animation;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnStart=(Button)findViewById(R.id.btnStart);
btnStop=(Button)findViewById(R.id.btnStop);
img=(ImageView)findViewById(R.id.imageView1);
img.setBackgroundResource(R.anim.animation_loding);
animation=(AnimationDrawable)img.getBackground();
btnStart.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
animation.start();
}
});
btnStop.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
animation.stop();
}
});
}
}
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/new1" android:duration="50" />
<item android:drawable="@drawable/new2" android:duration="50" />
<item android:drawable="@drawable/new3" android:duration="50" />
<item android:drawable="@drawable/new4" android:duration="50" />
<item android:drawable="@drawable/new5" android:duration="50" />
<item android:drawable="@drawable/new6" android:duration="50" />
<item android:drawable="@drawable/new7" android:duration="50" />
<item android:drawable="@drawable/new8" android:duration="50" />
<item android:drawable="@drawable/new9" android:duration="50" />
<item android:drawable="@drawable/new10" android:duration="50" />
<item android:drawable="@drawable/new11" android:duration="50" />
<item android:drawable="@drawable/new12" android:duration="50" />
</animation-list>
I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)
No comments:
Post a Comment