Android list view inside a scroll view

后端 未结 30 2054
一向
一向 2020-11-21 13:43

I have an android layout which has a scrollView with a number of elements with in it. At the bottom of the scrollView I have a listView

30条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-21 13:45

    Done after lots of R&D:

    fragment_one.xml should looks like:

    
    
    
        
    
            
    
                
    
                
            
    
            
    
        
    
    
    

    Your Java class of FragmentOne.java looks like:

    private ListView listView;
    private View customView
    

    onCreateView

    listView = (ListView) rootView.findViewById(R.id.listView);
    scrollViewParent = (ScrollView)rootView.findViewById(R.id.scrollViewParent);
    customView = (View)rootView.findViewById(R.id.customView);
    
    customView.setOnTouchListener(new View.OnTouchListener() {
    
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    int action = event.getAction();
                    switch (action) {
                        case MotionEvent.ACTION_DOWN:
                            // Disallow ScrollView to intercept touch events.
                            scrollViewParent.requestDisallowInterceptTouchEvent(true);
                            // Disable touch on transparent view
                            return false;
    
                        case MotionEvent.ACTION_UP:
                            // Allow ScrollView to intercept touch events.
                            scrollViewParent.requestDisallowInterceptTouchEvent(false);
                            return true;
    
                        case MotionEvent.ACTION_MOVE:
                            scrollViewParent.requestDisallowInterceptTouchEvent(true);
                            return false;
    
                        default:
                            return true;
                    }
                }
            });
    

提交回复
热议问题