android - 在 RecyclerView 中滚动 Textview

标签 android android-layout android-recyclerview

我有一个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/

相关文章:

java - 在 Android 游戏开发中使用的东西

java - Snackbar 重叠 View 而不是向上移动它;我怎样才能解决这个问题?

java - 如何在 Android 中将图像从 Drawable 文件夹存储到 SDCard?

android - 为什么 GridView 中的适配器不更新其内容?

android - CollapsingToolbarLayout 内的 ViewPager

android - 使用 Parse 推送通知错误

java - 如何更新 Firestore RecyclerView 中的项目?

机器人: fragment 的 Recyclerview?

android - 如何实现获取和返回 LifeCycle 的方法

android - CollapsingToolbarLayout 中的折叠状态下未显示后退按钮