The IOS common view has an auto-return animation effect. Android has implemented a color gradient animation effect starting from 2.3 when it is pushed down to the bottom and pushed up to the bottom. The View class has two important methods: scrollto and scrollby, allowing you to move the visible area of the view. This is the theoretical basis for implementing the animation effect today. We can drag down the list or the corresponding mobile data list at the top of the android data list, and let it play back when the drag is stopped. The following is the code:
Package com. Linghu;
Import Android. content. context;
Import Android. util. attributeset;
Import Android. View. motionevent;
Import Android. widget. listview;
Public class pull_listview extends listview implements runnable {
Private float mlastdowny = 0f;
Private int mdistance = 0;
Private int mstep = 10;
Private Boolean mpositive = false;
Public pull_listview (context, attributeset attrs ){
Super (context, attrs );
}
Public pull_listview (context, attributeset attrs, int defstyle ){
Super (context, attrs, defstyle );
}
Public pull_listview (context ){
Super (context );
}
@ Override
Public Boolean ontouchevent (motionevent event ){
Switch (event. getaction ()){
Case motionevent. action_down:
If (mlastdowny = 0f & mdistance = 0 ){
Mlastdowny = event. Gety ();
Return true;
}
Break;
Case motionevent. action_cancel:
Break;
Case motionevent. action_up:
If (mdistance! = 0 ){
Mstep = 1;
Mpositive = (mdistance> = 0 );
This. Post (this );
Return true;
}
Mlastdowny = 0f;
Mdistance = 0;
Break;
Case motionevent. action_move:
If (mlastdowny! = 0f ){
Mdistance = (INT) (mlastdowny-event. Gety ());
If (mdistance <0 & getfirstvisibleposition () = 0 & getchildat (0 ). gettop () = 0) | (mdistance> 0 & getlastvisibleposition () = getcount ()-1 )){
Mdistance/= 2;
Scrollto (0, mdistance );
Return true;
}
}
Mdistance = 0;
Break;
}
Return super. ontouchevent (event );
}
@ Override
Public void run (){
Mdistance + = mdistance> 0? -Mstep: mstep;
Scrollto (0, mdistance );
If (mpositive & mdistance <= 0) | (! Mpositive & mdistance> = 0 )){
Scrollto (0, 0 );
Mdistance = 0;
Mlastdowny = 0f;
Return;
}
Mstep + = 1;
This. postdelayed (this, 10 );
}
} // End class
The above is a relatively old code, and the effect may not be very good at all. See the following: the effect is very smooth.
Address: http://download.csdn.net/detail/linghu_java/5899421