Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在滚动视图中滚动日期选择器_Android_Datepicker_Android Scrollview - Fatal编程技术网

Android 如何在滚动视图中滚动日期选择器

Android 如何在滚动视图中滚动日期选择器,android,datepicker,android-scrollview,Android,Datepicker,Android Scrollview,基本上,我不能在日期选择器中滚动月份和年份,因为滚动视图是滚动的视图 <DatePicker android:layout_width="match_parent" android:id="@+id/datePicker5" android:layout_weight="3.61" android:layout_height="match_parent" /> 我不知道为什么它仍然不起作

基本上,我不能在日期选择器中滚动月份和年份,因为滚动视图是滚动的视图

<DatePicker
            android:layout_width="match_parent"
            android:id="@+id/datePicker5"
            android:layout_weight="3.61"
            android:layout_height="match_parent" />

我不知道为什么它仍然不起作用,请帮助。

在另一个可滚动视图中有一个可滚动视图不是一个好的做法。然而,要解决这个问题,您必须在用户与日期选择器交互时禁用父scrollview,如下所示-

date_picker.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
     if (event.getAction() == MotionEvent.ACTION_DOWN) {
      //  Disallow the touch request for parent scroll on touch of datepicker view
      requestDisallowParentInterceptTouchEvent(v, true);
     } 
     else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
     // Re-allows parent events
     requestDisallowParentInterceptTouchEvent(v, false);
     }
    return false;
    }
    });


private void requestDisallowParentInterceptTouchEvent(View v, Boolean disallowIntercept) {
    while (v.getParent() != null && v.getParent() instanceof View) {
        if (v.getParent() instanceof ScrollView) {
            v.getParent().requestDisallowInterceptTouchEvent(disallowIntercept);
        }
        v = (View) v.getParent();
    }
}

@DOOM博士你能分享你的完整xml文件吗?
date_picker.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
     if (event.getAction() == MotionEvent.ACTION_DOWN) {
      //  Disallow the touch request for parent scroll on touch of datepicker view
      requestDisallowParentInterceptTouchEvent(v, true);
     } 
     else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
     // Re-allows parent events
     requestDisallowParentInterceptTouchEvent(v, false);
     }
    return false;
    }
    });


private void requestDisallowParentInterceptTouchEvent(View v, Boolean disallowIntercept) {
    while (v.getParent() != null && v.getParent() instanceof View) {
        if (v.getParent() instanceof ScrollView) {
            v.getParent().requestDisallowInterceptTouchEvent(disallowIntercept);
        }
        v = (View) v.getParent();
    }
}