How to work, when listview inside the scrollview?

后端 未结 2 456
猫巷女王i
猫巷女王i 2020-12-05 05:44

I doing this In Android 1.6 and 2.2 ...

I have One ScrollView in the Activity (All the content in the ScrollView) ...

相关标签:
2条回答
  • 2020-12-05 06:25

    here parentScroll = your main scrollview and childScroll = your listview

    parentScroll.setOnTouchListener(new View.OnTouchListener() {
    
                    public boolean onTouch(View v, MotionEvent event) {
                        Log.v("PARENT", "PARENT TOUCH");
                        findViewById(R.id.child_scroll).getParent()
                                .requestDisallowInterceptTouchEvent(false);
                        return false;
                    }
                });
    
      childScroll.setOnTouchListener(new View.OnTouchListener() {
    
                    public boolean onTouch(View v, MotionEvent event) {
                        Log.v("CHILD", "CHILD TOUCH");
                        // Disallow the touch request for parent scroll on touch of
                        // child view
                        v.getParent().requestDisallowInterceptTouchEvent(true);
                        return false;
                    }
                });
    
    0 讨论(0)
  • 2020-12-05 06:25
       svView.setOnTouchListener(new 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)
提交回复
热议问题