When Android was resolved in ScrollView nested listview, listview can not scroll problem

Copyright: https://blog.csdn.net/yu805894501/article/details/80694722

       We sometimes use the Android layout to ScrollView, then nested listview in ScrollView in, but this will not lead to failure to obtain a focus listview scroll (the specific principles can search for their own distribution mechanisms Android touch event), the search solution It found that the program needs to be rewritten when ScrollView and listview, but the principle is the code I wrote the thing you could save on the province, so in accordance with the usual way of thinking, when we pressed down on the listview, let ScrollView lose focus, then lift your finger at us then let ScrollView can get the focus; the specific code as follows:

// for nested in listview scrollable view, the problem can not roll listview
 listItemView .setOnTouchListener ( new new View.OnTouchListener () {
     @Override
 public Boolean OnTouch (View V, the MotionEvent Event) {
         Switch (event.getAction ()) {
             / / when a finger touches the listview, so that the parent control the focus, not roll
 Case MotionEvent. ACTION_DOWN :
                 the scrollView .requestDisallowInterceptTouchEvent ( to true );
             Case MotionEvent. ACTION_MOVE :
                 BREAK ;                
           
            Case . MotionEvent ACTION_CANCEL :
                 // when you release your finger, let the parent control to re-gain focus
 the scrollView .requestDisallowInterceptTouchEvent ( false );
                 BREAK ;                
        }
        return false;
    }
});
 
 

Of course Xinyou controls can also be rewritten: provide a few links below, in addition to thank some of their methods (I have not done a test, does not guarantee the ability to use laughing out loud)

https://blog.csdn.net/leochen315531813/article/details/48683975

https://blog.csdn.net/sinat_28891771/article/details/71424975


Guess you like

Origin blog.csdn.net/yu805894501/article/details/80694722
Recommended