【问题标题】:How to disable scroll outside of NumberPicker element in Android如何在 Android 中禁用 NumberPicker 元素之外的滚动
【发布时间】:2023-03-10 02:32:01
【问题描述】:

我有一个靠近 Activity 底部的 NumberPicker 元素。当用户向下滚动时,会单击“返回”按钮。我想禁用 NumberPicker 区域之外的滚动。

数字选择器显示在返回按钮上方

似乎没有明确的选择。

这是片段内的 xml:


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="@string/string1_id" />

            <NumberPicker
                android:id="@+id/number_picker_id"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:background="@color/colorGray"></NumberPicker>
        </LinearLayout>

我希望当手指滚动经过 NumberPicker 区域时,NumberPicker 会停止滚动。

【问题讨论】:

    标签: java android numberpicker


    【解决方案1】:

    android LOLLIPOP版本以后可以使用这块代码

    number_pick_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
    
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            number_pick.stopNestedScroll();
        }
    
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2012-03-04
      • 1970-01-01
      • 1970-01-01
      • 2011-02-28
      • 2020-01-06
      • 1970-01-01
      • 2011-06-18
      相关资源
      最近更新 更多