Android scrollview inside another scrollview doesn't scroll

后端 未结 9 542
北恋
北恋 2020-12-10 02:36

I\'m trying to put a ScrollView inside another ScrollView and I tried the answers found on this site but it still doesn\'t seems to work completely. Here is the XML:

相关标签:
9条回答
  • 2020-12-10 03:16

    Here is a possible solution which works fine with ScrollView and ListView inside a ScrollView. ScrollView Inside ScrollView

    0 讨论(0)
  • 2020-12-10 03:18

    you can not use two Scrollview inside Scrollview OS get confuse which one have to scroll so your activity hang so do not use like this

    0 讨论(0)
  • 2020-12-10 03:19

    use this custom scrollview as inner scrollview:

    public class TouchMeScrollView extends ScrollView {
    public TouchMeScrollView(Context context) {
        super(context);
    }
    
    public TouchMeScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public TouchMeScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public TouchMeScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        requestDisallowInterceptTouchEvent(true);
        return super.onTouchEvent(ev);
    }
    }
    
    0 讨论(0)
  • 2020-12-10 03:24

    check this link which shows that how to use two widget with scroll functionality in same activity. check this below code in that.

    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-10 03:24

    I'm almost sure it is impossible:

    How android handles touch events:

    Parent gets event and decides if it has to handle it or if it should let handle it to the child;

    so,if a scrollview handles the touch, the one which handles it, is always the parent one

    http://developer.android.com/training/gestures/viewgroup.html

    personally i don't know if is there a way to understand what is touched behind the parent scrollview to see if it is another scrollview and let it handle the movement

    0 讨论(0)
  • 2020-12-10 03:25

    You should use NestedScrollView.

    <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                >
                <!-- -->
    </android.support.v4.widget.NestedScrollView>
    
    0 讨论(0)
提交回复
热议问题