使ListView在ScrollView中可以滚动

来源:互联网 发布:赌场 知乎 编辑:程序博客网 时间:2024/05/21 19:22

转自:http://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android

162楼解决了此问题

代码:

ListView lv = (ListView)findViewById(R.id.myListView);  // your listview inside scrollviewlv.setOnTouchListener(new ListView.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.                v.getParent().requestDisallowInterceptTouchEvent(true);                break;            case MotionEvent.ACTION_UP:                // Allow ScrollView to intercept touch events.                v.getParent().requestDisallowInterceptTouchEvent(false);                break;            }            // Handle ListView touch events.            v.onTouchEvent(event);            return true;        }    });


0 0