Android RecyclerView不会过度滚动
Recyclerview无法使用scrollview平滑滚动。如果我删除scrollview,它将变得更加平滑。我应该怎么做才能顺利滚动recyclerviewAndroid RecyclerView不会过度滚动,android,android-recyclerview,Android,Android Recyclerview,Recyclerview无法使用scrollview平滑滚动。如果我删除scrollview,它将变得更加平滑。我应该怎么做才能顺利滚动recyclerview <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.and
<?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>
您不应该将RecyclerView放在滚动视图中。如果您需要在RecyclerView的末尾显示页脚(即在RecyclerView的最后一项之后的视图),那么这也应该是RecyclerView的一部分。为此,只需在适配器中指定不同的项类型并返回相应的ViewHolder 首先在适配器中添加以下内容:
private class ViewType {
public static final int NORMAL = 0;
public static final int FOOTER = 1;
}
@Override
public int getItemViewType(int position) {
if(position == getCount() - 1)
return ViewType.FOOTER;
else
return ViewType.NORMAL;
}
然后,覆盖适配器的getCount(),并再添加一项:
@Override
public int getCount() {
return yourListsSize + 1;
}
接下来,您需要指定当前项的类型。要实现此目的,请覆盖适配器的getItemViewType():
private class ViewType {
public static final int NORMAL = 0;
public static final int FOOTER = 1;
}
@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文件中,以便在此处进行膨胀。通过“页脚布局”,我指的是带有android:id=“@+id/ll”
及其子视图的LinearLayout
希望这有帮助