【问题标题】:Staggeredgridview inside swiperefreshlayout goes empty on swipe refreshswiperefreshlayout 中的 Staggeredgridview 在刷卡刷新时变空
【发布时间】:2017-07-11 20:12:34
【问题描述】:

我在SwipeRefreshLayout 中有一个StaggeredGridview,当我使用滑动操作刷新网格时,即使我的列表不为空(数据),它也会变为空。 如果我使用LinearLayoutManager 而不是StaggeredGridLayoutManager 一切正常(我得到listView 而不是交错网格)。当我再次将LinearLayoutManager 更改为StaggeredGridLayoutManager 时,视图在刷新时变为空

这就是我将LinearLayoutManagerStaggeredGridLayoutManager 设置为我的recyclerView 的方式

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        recyclerView.addItemDecoration(new VerticalDividerItemDecoration(getActivity(), R.drawable.divider_discover));
        recyclerView.setLayoutManager(linearLayoutManager);

StaggeredGridLayoutManager stgaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, OrientationHelper.VERTICAL);
        recyclerView.setLayoutManager(stgaggeredGridLayoutManager);

感谢任何帮助。提前致谢。

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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipe_refresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="vertical" />
        </android.support.v4.widget.SwipeRefreshLayout>

    </FrameLayout>

    <TextView
        android:id="@+id/tv_empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="@string/list_empty"
        android:textSize="20sp"
        android:visibility="gone" />

</RelativeLayout>

【问题讨论】:

  • 好吧,我假设你在刷新后设置数据有问题。
  • @Ibrahim 感谢您的回复。我不这么认为,因为当我将 StaggeredGridLayoutManager 更改为 LinearLayoutManager 时它工作正常
  • 请提供recycleView xml代码。
  • @Ibrahim 用 recyclerView xml 代码更新了我的问题。

标签: android staggered-gridview staggeredgridlayout


【解决方案1】:

我用

解决了我的问题

在 notifyDataSetChanged() 之前重新附加布局管理器

                    recy_latest.setHasFixedSize(true);
                    layoutManager = new StaggeredGridLayoutManager(InitApplication.getLayoutCount(),StaggeredGridLayoutManager.VERTICAL);
                    recy_latest.setLayoutManager(layoutManager);
                    recy_latest.setItemAnimator(new DefaultItemAnimator());
                    wallpaperAdapter.notifyDataSetChanged();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多