结合之前的文章,关于RecyclerView加载图片,下面这篇文章:
http://blog.youkuaiyun.com/wb175208/article/details/53618862
但是在Item加载图片的时候,一般情况下要使用一个Loading动画以提高用户的体验,网上这样的示例很多。但是我使用的是SwipeRefreshLayout来实现加载动画。
1.首先是布局文件,要在RecyclerView外层包裹一层SwipeRefreshLayout:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v4.widget.SwipeRefreshLayout>
2.初始化控件:
private SwipeRefreshLayout mSwipeRefreshLayout;//刷新Loading
...
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.e_custom_merchandise_activity_swipe_layout);
//设置样式刷新显示的位置
mSwipeRefreshLayout.setProgressViewOffset(true, -20, 100);
mSwipeRefreshLayout.setColorSchemeResources(R.color.swiperefresh_color1);
mSwipeRefreshLayout.setEnabled(false);//禁用下拉刷新,只作为加载动画显示
3.使用
//开始刷新
mSwipeRefreshLayout.setRefreshing(true);
...
//停止刷新
mSwipeRefreshLayout.setRefreshing(false);
就是这么简单!