当我使用滑动操作刷新网格时,即使我的列表不为空(数据),我也有一个StaggeredGridview
内部 a 。SwipeRefreshLayout
如果我使用LinearLayoutManager
而不是StaggeredGridLayoutManager
一切正常(我得到一个listView
而不是交错网格)。当我再次更改LinearLayoutManager
为时StaggeredGridLayoutManager
,视图在刷新时为空
这就是我设置LinearLayoutManager
和StaggeredGridLayoutManager
我的方式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>