【发布时间】:2018-08-16 23:00:25
【问题描述】:
我正在使用 RecyclerView,它将用于加载潜在的许多图像,我希望在 RecyclerView 上方有一个操作栏,如下所示:
但我也希望操作栏的顶部只有灰色背景。如果用户滚动,它应该像这样完全透明:
通过使用它作为我的布局,我已经完成了我想要的(有一个主要问题):
fragment_recycler_gallery.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Gray bar at top -->
<View
android:id="@+id/gray_bar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@null" />
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
NestedScrollView 是让我的整个片段滚动而不只是 RecyclerView 滚动的关键,但它使我的应用程序在加载大量图像 (500+) 时变慢或无响应。有没有更好的方法来创建我正在寻找的东西?我试过寻找解决方案,但我只能找到“不要在nestedScrollViews 中使用recyclerviews”,而没有提供任何替代解决方案。
如果这也很重要,我正在使用 Glide 将图像加载到每个 ImageView(在 recyclerview 中)。
我已经在我的 RecyclerView 上使用了它:
mAlbumRecyclerView.setNestedScrollingEnabled(false);
【问题讨论】:
-
尝试在您的
onCreateViewHolder中添加日志,如果您看到超过 12 次调用,您已经搞砸了 recyclerView 的大小,因此它会立即生成所有视图。 -
您应该在以图标形式显示照片时考虑照片的大小。如果不加以考虑,它将大大降低性能。
标签: android android-recyclerview android-view android-nestedscrollview