How can I put a ListView into a ScrollView without it collapsing?

后端 未结 27 3330
轮回少年
轮回少年 2020-11-21 05:24

I\'ve searched around for solutions to this problem, and the only answer I can find seems to be \"don\'t put a ListView into a ScrollView\". I have yet to see any real expl

27条回答
  •  情深已故
    2020-11-21 05:59

    This will definitely work............
    You have to just replace your in layout XML file with this Custom ScrollView like

    package com.tmd.utils;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.MotionEvent;
    import android.widget.ScrollView;
    
    public class VerticalScrollview extends ScrollView{
    
        public VerticalScrollview(Context context) {
            super(context);
        }
    
         public VerticalScrollview(Context context, AttributeSet attrs) {
                super(context, attrs);
            }
    
            public VerticalScrollview(Context context, AttributeSet attrs, int defStyle) {
                super(context, attrs, defStyle);
            }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            final int action = ev.getAction();
            switch (action)
            {
                case MotionEvent.ACTION_DOWN:
                        Log.i("VerticalScrollview", "onInterceptTouchEvent: DOWN super false" );
                        super.onTouchEvent(ev);
                        break;
    
                case MotionEvent.ACTION_MOVE:
                        return false; // redirect MotionEvents to ourself
    
                case MotionEvent.ACTION_CANCEL:
                        Log.i("VerticalScrollview", "onInterceptTouchEvent: CANCEL super false" );
                        super.onTouchEvent(ev);
                        break;
    
                case MotionEvent.ACTION_UP:
                        Log.i("VerticalScrollview", "onInterceptTouchEvent: UP super false" );
                        return false;
    
                default: Log.i("VerticalScrollview", "onInterceptTouchEvent: " + action ); break;
            }
    
            return false;
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            super.onTouchEvent(ev);
            Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() );
             return true;
        }
    }
    

提交回复
热议问题