The effect is to right-swipe on an item to delete an entry-the effect is simple, but the idea is important
Mainactivity
Package Com.yangfuhai.animation1;import Java.util.arraylist;import Android.app.listactivity;import Android.os.bundle;import Android.view.motionevent;import Android.view.view;import Android.view.view.ontouchlistener;import Android.view.animation.animation;import Android.view.animation.animation.animationlistener;import Android.view.animation.animationutils;import Android.widget.adapterview;import Android.widget.arrayadapter;import Android.widget.listview;import Android.widget.toast;public class Mainactivity extends Listactivity {private arraylist<string> array;private arrayadapter<string> adapter; @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); ListView ListView = Getlistview (); array = new arraylist<string> (); String aa[] = {"Items1", "item2", "Items3", "Item4", "Items5", "Item6", "Items7", "ITEM8", "Items9", "ITEM10", "Items11", " Item12 "};for (int i = 0; i < aa.length; i++) {Array.add (aa[i]);} adapter = new arrayadapter<String> (this,android. R.layout.simple_list_item_1, array); Listview.setadapter (adapter); Listview.setontouchlistener (New Ontouchlistener () {float x, y, UPX, upy;public boolean onTouch (view view, Motionevent event) {if (event.getaction () = = Motionevent.action _down) {Toast.maketext (Mainactivity.this, "down", 0). Show (); x = Event.getx (); y = Event.gety ();} if (event.getaction () = = motionevent.action_up) {toast.maketext (Mainactivity.this, "up", 0). Show (); upx = Event.getx (); Upy = Event.gety ();//I interpret it as the position of X and Y to determine the position of this item in the ListView, int position1 = (ListView). Pointtoposition ((int) x, (int) y); int position2 = ((ListView) view). Pointtoposition ((int) upx, (int) upy); if (Position1 = = Position2 && upx > x&& math.abs (X-UPX) > () {View v = (ListView) view. Getchildat (Position1); Removelistitem (V, Position1 );}} return false;}}); Listview.setonitemclicklistener (New Adapterview.onitemclicklistener () {@Overridepublic void Onitemclick ( Adapterview<?> parent, View Rowview,int positon, long id) {Toast.maketext (Rowview.getcontext (), "you clicked the" + Positon + "position of item", Toast.length_short). Show ();}); }protected void Removelistitem (View rowview, final int positon) {final Animation Animation = (Animation) animationutils.lo Adanimation (Rowview.getcontext (), R.anim.item_anim); Animation.setanimationlistener (new AnimationListener () { public void Onanimationstart (Animation Animation) {}public void onanimationrepeat (Animation Animation) {}public void Onanimationend (Animation Animation) {array.remove (positon); adapter.notifydatasetchanged (); Animation.cancel ();}); Rowview.startanimation (animation);}}
Item_anim.xml
<?xml version= "1.0" encoding= "Utf-8"? ><translate xmlns:android= "http://schemas.android.com/apk/res/ Android " android:duration=" " android:fromxdelta=" 0 " android:fromydelta=" 0 " Android:toxdelta = "Android:toydelta=" " 0"/>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Slide-Slip Removal advanced (one)