Imitation QQ write a can play back and forth ScrollView.
You only need to rewrite ScrollView:
public class myscrollview extends scrollview { // The previous record position of the current touch point in the y direction private int previousY = 0; Start record position of touch point on // y direction private int startY = 0; Touch point on // y direction current record position private int currentY = 0; Relative distance between movement of two moves in // y direction private int deltaY = 0; // First sub-view private View childView; // used to record the initial position of the Childview private rect toprect = new rect (); public myscrollview (Context context) { super (context); } public Myscrollview (CONTEXT&NBSP;CONTEXT,&NBSp Attributeset attrs) { super (context, attrs); } public myscrollview (context context, Attributeset attrs, int defstyle) { super ( Context, attrs, defstyle); } @SuppressLint (" Missingsupercall ") @Override protected void Onfinishinflate () { if (Getchildcount () > 0) { childView = Getchildat (0); } } @Override public boolean dispatchtouchevent (motionevent event) { if (Null == childview) { return super.dispatchtouchevent (event); } switch (Event.getaction ()) { case MotionEvent.ACTION_DOWN: startY = (int) Event.gety (); previousy = starty; break; case motionevent.action_move: currentY = (int) &nbsP;event.gety (); deltaY = previousY - currentY; previousY = currentY; if (0 == getscrolly () | | childview.getmeasuredheight () - getheight () <= getscrolly ()) { // Record the initial position of the Childview if (Toprect.isempty ()) { Toprect.set (Childview.getleft (), childview.gettop (), childview.getright (), childview.getbottom ()); } // Update the location of Childview childview.layout (Childview.getleft (), childview.gettop () - deltay / 3, Childview.getright (), childview.getbottom () &NBSP;-&NBSP;DELTAY&NBSP;/&NBSP;3); } break; case motionevent.action_up: if (!toprect.isempty ()) { updownmoveanimation (); // child controls back to initial position childview.layout (topRect.left, toprect.top, toprect.right, toprect.bottom); } startY = 0; currentY = 0; Toprect.setempty (); break; default: break; } return super.dispatchtouchevent (Event); } // animation effect of the top and bottom rebound private void Updownmoveanimation () { translateanimation animation = new translateanimation (0.0f, 0.0f, childview.gettop (), toprect.top); animation.setduration (; ) Animation.setinterpolator (New accelerateinterpolator ()); Childview.setanimation (animation); }}
Then you can use the direct layout. This overriding method does not conflict with the click events of the child controls.
This article is from the "Android Development column" blog, be sure to keep this source http://liuyvhao.blog.51cto.com/11690759/1836527
Android imitation QQ rebound damping ScrollView