I wrote a layout of ListView controls embedded in HorizontalScrollView to solve the problem of sliding conflicts between them, so I rewrote the HorizontalScrollView interceptor code:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int x=(int)ev.getX();
int y=(int)ev.getY();
switch (ev.getAction()){
case MotionEvent.ACTION_DOWN:
intercepter=false;
Log.d(TAG,"ACTION_DOWN");
break;
case MotionEvent.ACTION_MOVE:
int deltX=x-lastX;
int deltY=y-lastY;
Log.d(TAG,"ACTION_MOVE");
Log.d(TAG,"Math.abs(deltX):"+Math.abs(deltX));
Log.d(TAG,"Math.abs(deltY):"+Math.abs(deltY));
if(Math.abs(deltX)>Math.abs(deltY)){
intercepter=true;
}else if(Math.abs(deltX)<Math.abs(deltY)){
intercepter=false;
}
break;
case MotionEvent.ACTION_UP:
Log.d(TAG,"ACTION_UP");
intercepter=false;
break;
}
lastY=y;
lastX=x;
Log.d(TAG,"intercepter:"+intercepter);
return intercepter;
}
but the strange thing is that I can slide normally in the HorizontalScrollView area, but I only get the MotionEvent.ACTION_DOWN event, but I don"t get the MotionEvent.ACTION_MOVE and MotionEvent.ACTION_UP events at all. Then I slide up and down in ListView, ListView can slide normally, but left and right can"t slide ScrollView, but at this time ScrollView actually gets the MotionEvent.ACTION_MOVE event, what is the reason for this?
the following is the information that slides around the ListView:
2018-12-02 14 intercepter:true intercepter:true
2018-12-02 14 intercepter:true intercepter:true
2018-12-02 14 purge 29.740 24256-24256/io.github.grooters.practicer 24256/io.github.grooters.practicer intercepter:false: intercepter:false
2018-12-02 14 Swiss 09VR 29.752 24256-24256/io.github.grooters.practicer DcrollViewer: ACTION_MOVE
2018-12-02 14 Swiss ScrollViewer: ACTION_MOVE
2018-12-02 14 Swiss ScrollViewer: 29.752 24256-24256/io.github.grooters.practicer DcrollViewer: Math.abs (deltX) < ScrollViewer: ACTION_MOVE
2018-12-02 14 Swiss ScrollViewer: 29.752 24256-ScrollViewer: ACTION_MOVE
2018-12-02 : 0
2018-12-02 14 Math.abs (deltY): Math.abs (deltY):: 29.752 24256-24256/io.github.grooters.practicer DcrollViewer: Math.abs (deltY): 0
2018-12-02 14 Swiss ScrollViewer 29.752 24256-24256/io.github.grooters.practicer DcrollViewer: intercepter:false
2018-12-02 14 purge 09Bloc 29.766 24256-24256/io.github.grooters.practicer DcrollViewer: ACTION_MOVE
2018-12-02 14Swiss 09Rank 29.766 24256-24256/io.github.grooters.practicer Viewer: scrollViewer: ScrollViewer: ACTION_MOVE
2018-12-02 14Swiss 09Rank 29.766 24256-ScrollViewer: ScrollViewer: 29766 24256-ScrollViewer: Math.abs (deltX): 18
2018-12-02 14 24256/io.github.grooters.practicer 24256/io.github.grooters.practicer Math.abs (deltY):: 29.766 24256-ScrollViewer: Math.abs (deltY): 10
2018-12-02 14 Fringe 09VR 29.766 24256-24256/io.github.grooters.practicer ScrollViewer: intercepter:true
intercepter are all true. We should have intercepted the sliding event. Why can"t we slide the HorizontalScrollView around? t T