Android:RecyclerView滚动问题

时间:2015-10-24 10:00:17

标签: android android-layout android-recyclerview

我有一个片段,其中包含Textview和RecyclerView(列表)

我的问题是当滚动RecyclerView时,它上面的textview保持在顶部并且不会滚动。

如何使文本视图像ScrollView一样非粘性和可滚动?

我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.easyuni.courserecommender.ResultsCareerTabFragment">

    <TextView
        android:id="@+id/tv_results_rec_careers_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center"
        android:layout_marginTop="24dp"
        android:text="@string/results_rec_careers_title"
        android:textSize="24sp"
        android:textStyle="bold" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_careers"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_results_rec_careers_title"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"></android.support.v7.widget.RecyclerView>

</RelativeLayout> 

截图:

正常看: enter image description here

在RecyclerView中向下滚动:enter image description here

感谢。

2 个答案:

答案 0 :(得分:1)

您需要将textview添加为为您的recyclerview提供适配器的项目。您可以使用以下代码来区分要在recyclerview中显示的视图:

public int getItemViewType (int position)

请看一下这个主题:

How to create RecyclerView with multiple view type?

答案 1 :(得分:0)

您可以使用以下方法修复它:

Message message = messageList.get(position);

viewHolder.setIsRecyclable(false);

你可以依靠这个链接:

http://www.homebrewandtechnology.com/blog/recyclevewadaptershowwrongdatawhenscrolling

相关问题