在 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/