2016-10-02 129 views
0

Recyclerview不滚动滚动视图。如果我删除滚动视图比它的光滑。我应该做些什么来顺利滚动recyclerview?RecyclerView不滚动滚动

<?xml version="1.0" encoding="utf-8"?> 
    <ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <RelativeLayout 
      android:id="@+id/content_activity_main" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      > 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/rv" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       /> 

      <LinearLayout 
       android:id="@+id/ll" 
       android:layout_width="match_parent" 
       android:layout_height="90dp" 
       android:layout_below="@+id/rv" 
       android:orientation="vertical"> 

       <ImageView 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:scaleType="fitXY" 
        /> 

       <TextView 
        android:id="@+id/textView35" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="8dp" 
        /> 

      </LinearLayout> 
     </RelativeLayout> 
    </ScrollView> 

回答

1

你不应该把你的RecyclerView放在一个ScrollView中。如果您需要在RecyclerView的末尾显示页脚(即在您的RecyclerView的最后一项之后显示一个视图),那么这也应该是RecyclerView的一部分。为此,您只需在适配器中指定不同的项目类型并返回相应的ViewHolder。适配器的

private class ViewType { 
     public static final int NORMAL = 0; 
     public static final int FOOTER = 1; 
} 

然后,覆盖getCount将(),并增加一个项目:

首先添加这在适配器

@Override 
public int getCount() { 
    return yourListsSize + 1; 
} 

接下来,你需要指定是哪个类型的是当前项目。为了实现这一目标,覆盖getItemViewType()适配器的:

@Override 
public int getItemViewType(int position) { 
    if(position == getCount() - 1) 
     return ViewType.FOOTER; 
    else 
     return ViewType.NORMAL; 
} 

最后,在onCreateViewHolder()检查当前项目的类型和膨胀适当的视图:

@Override 
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { 

    View rowView; 

    switch (viewType) { 
     case ViewType.NORMAL: 
      rowView=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.normal, viewGroup, false); 
      break; 
     case ViewType.FOOTER: 
      rowView=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.footer, viewGroup, false); 
      break; 
     default: 
      rowView=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.normal, viewGroup, false); 
      break; 
    } 
    return new ViewHolder(rowView); 
} 

当然,您还需要将您的页脚布局移动到单独的xml文件中,以便在此处使其膨胀。通过“页脚布局”,我指的是LinearLayoutandroid:id="@+id/ll"及其子视图。

希望这会有所帮助。