我有一个RecyclerView
<android.support.v7.widget.RecyclerView
android:id="@+id/activityRecicler"
android:layout_width="match_parent"
android:scrollbars="vertical"
android:layout_height="wrap_content"
app:stackFromEnd="true"
/>
我有一个行布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/description"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/solutions"/>
</LinearLayout>
包装内容有效,但我的问题是带有 id 描述的 TextView
它可能很长,因此,我会为此 TextView 设置一个 Scroll。
我怎么能这样做?
最佳答案
将您的布局 XML 更改为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
<TextView
android:id="@+id/solutions"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
然后在您的 Activity 中:
recyclerView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
findViewById(R.id.scroll_view).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
scrollView.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;
}
});
关于android - 在 RecyclerView 中滚动 Textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38741787/