Nonsense not to say more, directly to everyone to paste the code, the specific code as follows:
Package demo.hq.com.fby;
Import Android.content.Context;
Import Android.util.AttributeSet;
Import Android.util.Log;
Import android.view.MotionEvent;
Import Android.widget.LinearLayout;
/** * Created by huqing on 2016/12/7. * Train of thought: * The external intercept * in the parent layout, onintercepttouchevent first to determine whether to intercept the slide, true to intercept the direct entry into the parent layout of the Ontouch method; False Enter Ontouch method of sub layout/public class
Myparentview extends LinearLayout {/** * The distance moved by move downward/private int mmove;
/** * The position of the drop point * * private int ydown;
/** * Move Point position * * private int ymove;
/** * A total downward moving distance * * Private int downdistance = 0;
Public Myparentview (context, AttributeSet attrs) {Super (context, attrs);
Boolean intercept = false;
/** * External Intercept, * if it is a downward slide is true, to the control to handle, up false to the child control to handle it * so up the event child control can get the * * @param EV * @return * * @Override public boolean onintercepttouchevent (motionevent ev) {switch (ev.getaction ()) {case Motion Event.ACTION_DOWN:yDown = (int) ev.getY ();
Break
Case MotionEvent.ACTION_MOVE:yMove = (int) ev.gety ();
if (Ymove > Ydown) {intercept = true;
LOG.D ("Hqq", "intercept ~~~~~~~~~~~~~~~~~~");
else if (Ymove < Ydown) {intercept = false;
LOG.D ("Hqq", "Do not intercept ~~~~~~~~~~~~~~~~~~");
} break;
Case MotionEvent.ACTION_UP:break;
//true Intercept, enter the control's Ontouchevent method false: Enter the Ontouchevent boolean returnintercept = intercept of the child control;
Intercept = false;
return returnintercept;
@Override public boolean ontouchevent (Motionevent event) {log.e ("HQ", "Father Ontouch");
int y = (int) event.gety ();
Switch (event.getaction ()) {case MotionEvent.ACTION_DOWN:yDown = y;
Break
Case MotionEvent.ACTION_MOVE:if (downdistance>=250) {}else {ymove = y; if (Ymove-ydown > 0) {mmove = Ymove-ydoWn
Downdistance + = Mmove;
if (downdistance>=250) {layout (GetLeft (), Downdistance, GetRight (), getheight () + downdistance);
}else {layout (GetLeft (), GetTop () + Mmove, GetRight (), Getbottom () + mmove);
}} break;
Case MotionEvent.ACTION_UP:layout (GetLeft (), GetTop ()-Downdistance, GetRight (), Getbottom ()-downdistance);
downdistance = 0;
Break
Return to true;//return Super.ontouchevent (event);
}
}
package demo.hq.com.fby; import android.content.Context; import
Android.util.AttributeSet;
Import Android.util.Log;
Import android.view.MotionEvent;
Import Android.widget.ScrollView;
/** * Created by huqing on 2016/12/7. * * public class Myscrollview extends ScrollView {public Myscrollview (context, AttributeSet attrs) {Super
(context, attrs);
@Override public boolean ontouchevent (motionevent ev) {LOG.E ("HQ", "Child Ontouch----------------");
Switch (ev.getaction ()) {case MotionEvent.ACTION_DOWN:getParent (). Requestdisallowintercepttouchevent (True);
Break Case MotionEvent.ACTION_MOVE:if (getscrolly () ==0) {//scrollview allows the parent control to intercept GetParent () if the sliding height does not change without sliding. req
Uestdisallowintercepttouchevent (FALSE);
}else {//Prohibit interception of GetParent (). Requestdisallowintercepttouchevent (True);
} break;
return super.ontouchevent (EV); }
}
<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout android:id= "@+id/activity_main" xmlns:android= "http ://schemas.android.com/apk/res/android "xmlns:tools=" Http://schemas.android.com/tools "android:layout_width=" Match_parent "android:layout_height=" match_parent "android:background=" @drawable/bg "tools:context=" Demo.hq.com.fby.MainActivity "> <demo.hq.com.fby.myparentview android:layout_width=" match_parent "android:l
ayout_height= "Wrap_content" android:background= "#ffffff" android:orientation= "vertical" > <textview Android:layout_width= "Wrap_content" android:layout_height= "100DP" android:text= "world!" /> <textview android:layout_width= "wrap_content" android:layout_height= "100DP" android:text= " world! " /> <demo.hq.com.fby.myscrollview android:layout_width= "match_parent" android:layout_height= "W" Rap_content "> <linearlayout android:layout_width=" MatCh_parent "android:layout_height=" wrap_content "android:orientation=" vertical "> <t Extview android:layout_width= "wrap_content" android:layout_height= "200DP" android:text= "Hell" o world! "
/> <textview android:layout_width= "wrap_content" android:layout_height= "200DP" android:text= "Hello world!" /> </LinearLayout> </demo.hq.com.fby.MyScrollView> </demo.hq.com.fby.MyParentView> </r Elativelayout>
The above is a small set to introduce the Android sliding intercept example code analysis, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!