android - Using Listview in a scroll view -
In my app I scrolled inside the scrollview layout (the root layout). When I did this, I found a solution code for it
childlistview.setOnTouchListener (New ListView.OnTouchListener () {@ Override Public Boolean On-Touch (see We, Motion Event Event) { / TODO auto-generated method stub int Action = event.getAction (); switch (action) {case MotionEvent.ACTION_DOWN: v.getParent (). RequestDisallowInterceptTouchEvent (true); break; Case MotionEvent.ACTION_UP: v.getParent ( ). RequestDisallowInterceptTouchEvent (false); break;} V.onTouchEvent (event); return back;}}); The solution to this problem. But I can not understand this code Can anyone help?
In your case, scrollview is original, while ListView < / code> is her child. So, in the normal case when you try to scroll, ScrollView will stop the event and scroll to ScrollView . It will not reach within ListView because it is already handlled by parent ScrollView . However, when you set TouchListener override the child list view and its onTouch () , as you Have done, a different behavior is seen. Case motion event. Action_DOWN: This event occurs when the first finger is pressed on the screen.
v .getParent () requestDisallowInterceptTouchEvent (true); This will prevent the parents from blocking the touch event, so that the child can handle the incident properly.
Case motion event. Action_UP: This event occurs when all fingers are away from the screen.
v.getParent (). RequestDisallowInterceptTouchEvent (wrong); It will then allow parents to keep touch events in the middle, leaving the child-vision for the rest of the screen.
Hope this will help you.
Comments
Post a Comment