This article illustrates the way Android programming realizes the dithering effect of the iphone. Share to everyone for your reference, specific as follows:
Layout file:
<?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 " > <linearlayout android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:orientation=
"Horizontal" > <textview android:id= "@+id/tv0" android:layout_width= "80dip" android:layout_height= "94dip" android:drawabletop= "@drawable/ic_launcher" android:text= "@string/hello"/> <textview android:id= "@+id/tv 1 "android:layout_width=" 80dip "android:layout_height=" 94dip "android:drawabletop=" @drawable/ic_launcher "Andr oid:text= "@string/hello"/> <textview android:id= "@+id/tv2" android:layout_width= "80dip" Android:layout_h eight= "94dip" android:drawabletop= "@drawable/ic_launcher" android:text= "@string/hello"/> <textview Andro Id:id= "@+id/tv3" android:layout_width= "80dip "android:layout_height=" 94dip "android:drawabletop=" "@drawable/ic_launcher" android:text= "@string/hello"/&G
T </LinearLayout> <linearlayout android:layout_width= "fill_parent" android:layout_height= "Wrap_content" and roid:orientation= "Horizontal" > <textview android:id= "@+id/tv4" android:layout_width= "80dip" android:layou t_height= "94dip" android:drawabletop= "@drawable/ic_launcher" android:text= "@string/hello"/> <textview Droid:id= "@+id/tv5" android:layout_width= "80dip" android:layout_height= "94dip" android:drawabletop= "@drawable/ic_
Launcher "android:text=" @string/hello "/> <textview android:id=" @+id/tv6 "android:layout_width=" 80dip " android:layout_height= "94dip" android:drawabletop= "@drawable/ic_launcher" android:text= "@string/hello"/> < TextView android:id= "@+id/tv7" android:layout_width= "80dip" android:layout_height= "94dip" android:drawabletop= "@drawable/ic_launcheR "android:text=" @string/hello "/> </LinearLayout> <linearlayout android:layout_width=" Fill_parent "a ndroid:layout_height= "wrap_content" android:orientation= "horizontal" > <textview android:id= "@+id/tv8" Andr Oid:layout_width= "80dip" android:layout_height= "94dip" android:drawabletop= "@drawable/ic_launcher" android:text= " @string/hello "/> <textview android:id=" @+id/tv9 "android:layout_width=" 80dip "android:layout_height=" 94d IP "android:drawabletop=" @drawable/ic_launcher "android:text=" @string/hello "/> <textview android:id=" @+i
D/tv10 "android:layout_width=" 80dip "android:layout_height=" 94dip "android:drawabletop=" @drawable/ic_launcher " android:text= "@string/hello"/> <textview android:id= "@+id/tv11" android:layout_width= "80dip" Android:la yout_height= "94dip" android:drawabletop= "@drawable/ic_launcher" android:text= "@string/hello"/> </linearlayo
Ut> <linearlayout Android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:orientation= "Horizontal" > < TextView android:id= "@+id/tv12" android:layout_width= "80dip" android:layout_height= "94dip" android:drawabletop = "@drawable/ic_launcher" android:text= "@string/hello"/> <textview android:id= "@+id/tv13" Android:layout_ Width= "80dip" android:layout_height= "94dip" android:drawabletop= "@drawable/ic_launcher" android:text= "@string/hel Lo "/> <textview android:id=" @+id/tv14 "android:layout_width=" 80dip "android:layout_height=" 94dip "and
roid:drawabletop= "@drawable/ic_launcher" android:text= "@string/hello"/> <textview android:id= "@+id/tv15" Android:layout_width= "80dip" android:layout_height= "94dip" android:drawabletop= "@drawable/ic_launcher" android:t ext= "@string/hello"/> </LinearLayout> <linearlayout android:layout_width= "Fill_parent" Android:layout_ Height= "Wrap_content" android:orientation= "Horizontal" > <textview android:id= "@+id/tv16" android:layout_width= "80dip" Android:lay
out_height= "94dip" android:drawabletop= "@drawable/ic_launcher" android:text= "@string/hello"/> <textview Android:id= "@+id/tv17" android:layout_width= "80dip" android:layout_height= "94dip" android:drawabletop= "@drawable Ic_launcher "android:text=" @string/hello "/> <textview android:id=" @+id/tv18 "android:layout_width=" 80dip
"Android:layout_height=" 94dip "android:drawabletop=" "@drawable/ic_launcher" android:text= "@string/hello"/> <textview android:id= "@+id/tv19" android:layout_width= "80dip" android:layout_height= "94dip" android:drawabl
etop= "@drawable/ic_launcher" android:text= "@string/hello"/> </LinearLayout> </LinearLayout>
Code:
Package com.android.shake;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.util.DisplayMetrics;
Import android.view.animation.Animation;
Import Android.view.animation.Animation.AnimationListener;
Import android.view.animation.RotateAnimation;
Import Android.widget.TextView;
Import Android.view.View;
Import Android.view.Window;
public class Shaketestactivity extends activity implements View.onclicklistener {private TextView mtv0;
Private TextView MTV1;
Private TextView MTV2;
Private TextView MTV3;
Private TextView MTV4;
Private TextView MTV5;
Private TextView MTV6;
Private TextView mtv7;
Private TextView MTV8;
Private TextView MTV9;
Private TextView mtv10;
Private TextView mtv11;
Private TextView mtv12;
Private TextView mtv13;
Private TextView mtv14;
Private TextView mtv15;
Private TextView mtv16;
Private TextView mtv17;
Private TextView mtv18;
Private TextView mtv19;
Private Boolean mneedshake = false;
Private Boolean mstartshake = false;private static final int icon_width = 80;
private static final int icon_height = 94;
Private static final float degree_0 = 1.8f;
Private static final float degree_1 = -2.0f;
Private static final float degree_2 = 2.0f;
Private static final float degree_3 = -1.5f;
Private static final float degree_4 = 1.5f;
private static final int animation_duration = 80;
private int mcount = 0;
float mdensity; /** called the activity is a.
* * @Override public void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Requestwindowfeature (Window.feature_no_title);
Setcontentview (R.layout.main);
Displaymetrics dm = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
if (DM!= null) {mdensity = dm.density;
} mtv0 = (TextView) Findviewbyid (r.id.tv0);
Mtv0.setonclicklistener (this);
MTV1 = (TextView) Findviewbyid (R.ID.TV1);
Mtv1.setonclicklistener (this);
MTV2 = (TextView) Findviewbyid (R.ID.TV2); Mtv2.setonClicklistener (this);
MTV3 = (TextView) Findviewbyid (R.ID.TV3);
Mtv3.setonclicklistener (this);
MTV4 = (TextView) Findviewbyid (R.ID.TV4);
Mtv4.setonclicklistener (this);
MTV5 = (TextView) Findviewbyid (R.ID.TV5);
Mtv5.setonclicklistener (this);
MTV6 = (TextView) Findviewbyid (R.ID.TV6);
Mtv6.setonclicklistener (this);
MTV7 = (TextView) Findviewbyid (R.ID.TV7);
Mtv7.setonclicklistener (this);
MTV8 = (TextView) Findviewbyid (R.ID.TV8);
Mtv8.setonclicklistener (this);
MTV9 = (TextView) Findviewbyid (R.ID.TV9);
Mtv9.setonclicklistener (this);
MTV10 = (TextView) Findviewbyid (R.ID.TV10);
Mtv10.setonclicklistener (this);
Mtv11 = (TextView) Findviewbyid (R.ID.TV11);
Mtv11.setonclicklistener (this);
MTV12 = (TextView) Findviewbyid (R.ID.TV12);
Mtv12.setonclicklistener (this);
Mtv13 = (TextView) Findviewbyid (R.ID.TV13);
Mtv13.setonclicklistener (this);
Mtv14 = (TextView) Findviewbyid (R.ID.TV14);
Mtv14.setonclicklistener (this); Mtv15 = (TextView) Findviewbyid (r.id.tV15);
Mtv15.setonclicklistener (this);
Mtv16 = (TextView) Findviewbyid (R.ID.TV16);
Mtv16.setonclicklistener (this);
Mtv17 = (TextView) Findviewbyid (R.ID.TV17);
Mtv17.setonclicklistener (this);
MTV18 = (TextView) Findviewbyid (R.ID.TV18);
Mtv18.setonclicklistener (this);
mtv19 = (TextView) Findviewbyid (r.id.tv19);
Mtv19.setonclicklistener (this);
@Override public void OnClick (View v) {if (!mstartshake) {mstartshake = true;
Mneedshake = true;
Shakeanimation (MTV0);
Shakeanimation (MTV1);
Shakeanimation (MTV2);
Shakeanimation (MTV3);
Shakeanimation (MTV4);
Shakeanimation (MTV5);
Shakeanimation (MTV6);
Shakeanimation (MTV7);
Shakeanimation (MTV8);
Shakeanimation (MTV9);
Shakeanimation (MTV10);
Shakeanimation (MTV11);
Shakeanimation (MTV12);
Shakeanimation (MTV13);
Shakeanimation (MTV14);
Shakeanimation (MTV15);
Shakeanimation (MTV16);
Shakeanimation (MTV17);
Shakeanimation (MTV18);
Shakeanimation (MTV19); } Private VOID shakeanimation (Final View v) {float rotate = 0;
int c = mcount++% 5;
if (c = = 0) {rotate = Degree_0;
else if (c = = 1) {rotate = degree_1;
else if (c = = 2) {rotate = degree_2;
else if (c = = 3) {rotate = degree_3;
else {rotate = degree_4; Final Rotateanimation MRA = new Rotateanimation (rotate,-rotate, icon_width * MDENSITY/2, Icon_height * MDENSITY/2
);
Final Rotateanimation MRB = new Rotateanimation (-rotate, rotate, icon_width * mdensity/2, Icon_height * MDENSITY/2);
Mra.setduration (animation_duration);
Mrb.setduration (animation_duration); Mra.setanimationlistener (New Animationlistener () {@Override public void Onanimationend (Animation Animation) {i
F (mneedshake) {mra.reset ();
V.startanimation (MRB); @Override public void Onanimationrepeat (Animation Animation) {} @Override public void Onanimationst
Art (Animation Animation) {}}); Mrb.setanimationlistener (New AnimatIonlistener () {@Override public void Onanimationend (Animation Animation) {if (Mneedshake) {mrb.reset ();
V.startanimation (MRA); @Override public void Onanimationrepeat (Animation Animation) {} @Override public void Onanimationst
Art (Animation Animation) {}});
V.startanimation (MRA);
@Override public void onbackpressed () {if (!mneedshake) {super.onbackpressed ();
else {mneedshake = false;
Mcount = 0;
Mstartshake = false;
}
}
}
Full instance code code click here to download the site.
I hope this article will help you with the Android program.