android - RecyclerView 中特定 TextView 的滚动条不起作用

标签 android android-layout listview android-fragments

在 fragment 中,我想在 RecyclerView 中滚动 TextView,所以我将 Scrollbar 放在 RecyclerView 中,但它在移动设备中不起作用,但在模拟器中运行良好,并且还尝试了嵌套 ScrollView ,但也有同样的问题。

如果我想滚动 Recyclerview 中的特定 TextView ,我该怎么办

ex.recyclerview ex 中有多个属性。用于用户照片的 ImageView 用于用户名的 TextView 和用于用户详细信息的 TextView ,因为用户详细信息字段很长我想单独滚动此字段

 <android.support.v4.widget.NestedScrollView
    android:id="@+id/bodyScroller"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:fillViewport="false">

<com.user.consulting_implantologist.MyText2
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="16dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:id="@+id/DrDetail"
    android:text="Detail"
    android:layout_marginBottom="15dp"
    android:textColor="@color/colorApp" />
   </android.support.v4.widget.NestedScrollView>

最佳答案

在您的 Layout.xml 文件中,您可以使用以下代码:

<ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/scrollText"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="long_text"
            android:maxLines="5"
            android:scrollbars="vertical"/>
    </ScrollView>

以下代码用于您 ViewHolder 文件 :
public ViewHolder(View itemView) {
            super(itemView);
            scrollText = (TextView) itemView.findViewById(R.id.scrollText);
            scrollView = (ScrollView) itemView.findViewById(R.id.scrollView);


            scrollText.setOnTouchListener(new View.OnTouchListener() {

                public boolean onTouch(View v, MotionEvent event) {
                    // Disallow the touch request for parent scroll on touch of child view
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    return false;
                }
            });

            //Enabling scrolling on TextView.
            scrollText.setMovementMethod(new ScrollingMovementMethod());
        }

关于android - RecyclerView 中特定 TextView 的滚动条不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49407247/

相关文章:

android - 如何使用自定义适配器和 ListView 获取复选框值

java - 如何解决 Android 4.4.2 中的 AVD 自动旋转屏幕问题?

java - 如何用图像按钮替换设置项

java - 将 TextView 动态添加到相对布局。

android - 不支持的操作异常 : Can't convert to dimension: type=0x1

android - 如何在我的类中不扩展 ListActivity 的情况下使用 ListView ?

android - Android ListView 中未显示顶部和底部分隔符

Android Coverflow OnClickListener

java - ADK Java 检查日期是否等于定义的日期间隔

java - 无法在同一 Activity 中用 fragment B 替换 fragment A