RecyclerView 购物车功能

前言: 

  RecyclerView是android 最常见的列表控件,它现在几乎已经代替了listVIew和GridView的使用,RecyclerView自带强大的功能,实现多种样式,使用更加简单,封装也很容易,相对于listIView,RecyclerView没有自己的item点击事件,需要开发人员自行通过接口回调来实现点击事件,在近期工作不忙时,我查阅了一些开源的商城项目,写了一套很全面的商城app的购物车功能的demo。

闲话少说先上运行图:

        

就上传这三张图,了解下大致功能。

1.项目搭配代码进行分析(这里只提供主要方法,详细的demo最下方分享)

1),个数的增加与减少实现:

自定义一个类,继承LinearLayoutb (AddSubView)

对加减按钮进行编写

 

通过回调方法进行回调

响应回调方法

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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="#fff">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_marginLeft="30dp"
            android:layout_weight="1"
            android:text="购物车"
            android:textColor="#303235"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/tv_shopcart_edit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="编辑"
            android:textColor="#303235" />
    </RelativeLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:background="#eeee" />

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


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:layout_height="0dp"
                android:background="#eee" />

            <LinearLayout
                android:id="@+id/ll_check_all"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#fff"
                android:orientation="horizontal"
                android:visibility="visible">

                <CheckBox
                    android:id="@+id/checkbox_all"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:button="@null"
                    android:drawableLeft="@drawable/checkbox_selector"
                    android:drawablePadding="10dp"
                    android:padding="10dp"
                    android:paddingLeft="0dp"
                    android:text="全选"
                    android:textColor="#303235"
                    android:textSize="15sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:text="合计:
  • 5
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值