用xrecyclerview做优惠券列表
来源:互联网 发布:java 计算调用时间 编辑:程序博客网 时间:2024/04/29 14:17
首先,上成功之后的效果图
接下来从gradle导入
compile 'com.jcodecraeer:xrecyclerview:1.3.2'
然后上布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.zhangshuyang01.coupondemo.MainActivity" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="优惠券Demo" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <RelativeLayout android:id="@+id/rl_empty" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:src="@mipmap/wallet_no_coupon" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="130dp" android:visibility="gone" android:text="邀请好友进行分享" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="-10dp" android:background="#f5f5f5"> <com.jcodecraeer.xrecyclerview.XRecyclerView android:id="@+id/xrv_list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbarSize="0.5dp" android:scrollbars="vertical" /> </RelativeLayout> </LinearLayout></LinearLayout>
adapter中item的布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ll_item" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="6dp" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="110dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@mipmap/user_wallet_coupon"> <LinearLayout android:id="@+id/rl_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_centerVertical="true" android:layout_marginLeft="35dp"> <TextView android:id="@+id/tv_use_time1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2" android:includeFontPadding="false" android:textColor="#333333" android:textSize="35sp"/> <TextView android:layout_alignParentBottom="true" android:id="@+id/tv_unit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:includeFontPadding="false" android:layout_marginLeft="10dp" android:layout_toRightOf="@id/tv_use_time1" android:text="小时" android:textColor="#333333" android:textSize="13sp"/> </LinearLayout> <View android:id="@+id/line" android:layout_width="0.5dp" android:layout_height="match_parent" android:layout_marginBottom="18dp" android:layout_marginLeft="18dp" android:layout_marginTop="18dp" android:layout_toRightOf="@id/rl_time" android:background="#dcdcdc"/> <RelativeLayout android:id="@+id/rl_text" android:layout_width="wrap_content" android:layout_height="60dp" android:layout_centerVertical="true" android:layout_marginLeft="18dp" android:layout_toRightOf="@+id/line"> <TextView android:id="@+id/tv_coupon_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用车券" android:textColor="#333333" android:textSize="24sp"/> <RelativeLayout android:id="@+id/rl_bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true"> <TextView android:id="@+id/tv_coupon_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="有效期至2017-01-10" android:textColor="#666666" android:textSize="13sp"/> </RelativeLayout> </RelativeLayout> </RelativeLayout></LinearLayout>
主程序中的代码
public class MainActivity extends AppCompatActivity { private XRecyclerView xRecyclerView; private RelativeLayout rl_empty; private int page=1,total_page,isOnRefresh=1; private ArrayList<Map<String,String>> mapList ; private MyCouponAdapter mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); xRecyclerView = (XRecyclerView) findViewById(R.id.xrv_list); rl_empty = (RelativeLayout) findViewById(R.id.rl_empty); init(); LinearLayoutManager layoutManager = new LinearLayoutManager(this); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); xRecyclerView.setLayoutManager(layoutManager); xRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader); xRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.Pacman); xRecyclerView.setEmptyView(rl_empty); xRecyclerView.setLoadingMoreEnabled(true); xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() { @Override public void onRefresh() { page=1; isOnRefresh=2; } @Override public void onLoadMore() { if (total_page-page>0){ page++; }else { xRecyclerView.loadMoreComplete(); } } }); mAdapter = new MyCouponAdapter(mapList); xRecyclerView.setAdapter(mAdapter); } public void init() { mapList = new ArrayList<>(); for (int i = 1; i < 10; i++) { Map<String, String> maps = new HashMap<>(); maps.put("number", ""+i); maps.put("unit", ""+i); maps.put("description", "描述"+i); maps.put("failtrue_time", "2018/"+i); mapList.add(maps); } }}
大功告成!有更好的改进方法或者错误的地方,请大家指出,谢谢~
github上有源码,欢迎下载
- https://github.com/beibeiMary
阅读全文
0 0
- 用xrecyclerview做优惠券列表
- 搜索商品+XRecyclerview展示列表
- XRecyclerView
- XrecyclerView
- XRecyclerView
- xrecyclerview
- xrecyclerview
- xrecyclerview
- XRecyclerView
- XRecyclerView实现RecyclerView下拉刷新上来加载 自己做了部分修改,使代码更简洁易用
- XRecyclerView和万能baseeAdapter 实现上拉下拉刷新列表
- XRecyclerView的多条目加载(banner+列表)
- 怎么用云服务器优惠券
- CSS3技巧:利用css3径向渐变做一张优惠券
- 用jquery模仿做下拉列表
- MVP和sqlite数据库,XRecyclerView上啦加载下拉刷新的第三方注册登录,列表
- MVP+XRecyclerView+okhttp+glide,列表或者网格显示所加载的数据
- OkHttp+Xrecyclerview
- Android混淆详解
- 一个tomcat下面启动多个工程
- mac下取消AppStore正在下载的程序
- 2017.07.19
- 【uva1362】Exploring Pyramids
- 用xrecyclerview做优惠券列表
- Python引用计数的三种方式
- ng-bind-html和.$compile的使用
- 阿里云服务器Linux下配置web服务环境
- 算法导论5.1-3
- win10系统怎么设置uefi启动?超详细教程献上!
- JAVAWEB开发之Lucene详解——Lucene入门及使用场景、全文检索、索引CRUD、优化索引库、分词器、高亮、相关度排序、各种查询
- 用math.abs打印菱形boolean和嵌套for分别打印空心三角形
- iOS开发的动态曲线图绘制