超级炫酷Recyclerview高级下拉刷新飞入等待动画效果
程序员文章站
2021-12-25 10:56:50
...
很久没有分享Android相关的Demo程序了、今天给大家带了福利了、一个特别棒的下拉刷新Demo、当你用手指下拉RecyclerView的时候、会从下方飞入一些食材、比如胡萝卜、面包鸡蛋之类的食材、Demo非常适合用在菜谱类的App上面使用、下面是动画的GIF图片、先来预览一下吧
XML代码
<?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" xmlns:app="http://schemas.android.com/apk/res-auto"> <com.yalantis.pulltomakesoup.PullToRefreshView android:id="@ id/pull_to_refresh" app:type="soup" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@ id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="@null" android:dividerHeight="0dp" android:fadingEdge="none"/> </com.yalantis.pulltomakesoup.PullToRefreshView> </RelativeLayout>
初始化代码
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(new SampleAdapter()); mPullToRefreshView = (PullToRefreshView) findViewById(R.id.pull_to_refresh); mPullToRefreshView.setOnRefreshListener(new PullToRefreshView.OnRefreshListener() { @Override public void onRefresh() { mPullToRefreshView.postDelayed(new Runnable() { @Override public void run() { mPullToRefreshView.setRefreshing(false); } }, REFRESH_DELAY); } });
Adapter代码
private class SampleAdapter extends RecyclerView.Adapter<SampleHolder> { @Override public SampleHolder onCreateViewHolder(ViewGroup parent, int pos) { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.list_item, parent, false); return new SampleHolder(view); } @Override public void onBindViewHolder(SampleHolder holder, int pos) { Map<String, Integer> data = mSampleList.get(pos); holder.bindData(data); } @Override public int getItemCount() { return mSampleList.size(); } }
recyclerview下拉刷新动画源代码下载链接: recyclerview下拉动画 密码: 5xgx
上一篇: Prometheus安装配置