购物车+MVP+二级列表

来源:互联网 发布:网络技术培训机构 编辑:程序博客网 时间:2024/06/12 19:45

效果图:

权限:

    <uses-permission android:name="android.permission.INTERNET" />    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

依赖:


    compile 'com.squareup.okio:okio:1.5.0'    compile 'com.squareup.okhttp3:okhttp:3.2.0'    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'    compile 'com.google.code.gson:gson:2.8.2'    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'

view层:创建接口,用Activity实现

1.定义接口

public interface IMainListener {    void getSuccessCartData(GetCartBean getCartBean);}
2.Activity实现
public class MainActivity extends AppCompatActivity implements IMainListener, View.OnClickListener{    private CartPresenter cartPresenter;    private CartExpanableListview expanableListview;    private Gson gson;    private MyAdapter myAdapter;    private CheckBox check_all;    private TextView text_total;    private TextView text_buy;    private Handler handler = new Handler(){        @Override        public void handleMessage(Message msg) {            if (msg.what == 0){                PriceAndCount countPriceBean = (PriceAndCount) msg.obj;                //设置                text_total.setText("合计:¥"+countPriceBean.getPrice());                text_buy.setText("去结算("+countPriceBean.getCount()+")");            }else  if (msg.what == 1){//改变全选                boolean flag = (boolean) msg.obj;                check_all.setChecked(flag);            }        }    };    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        cartPresenter = new CartPresenter(this);        cartPresenter.getDataJson(API.CARTURL);        check_all = (CheckBox) findViewById(R.id.check_all);        text_total = (TextView) findViewById(R.id.text_total);        text_buy = (TextView) findViewById(R.id.text_buy);        expanableListview = (CartExpanableListview) findViewById(R.id.expanable_listview);        //去掉默认的指示器        expanableListview.setGroupIndicator(null);        //全选:...点击事件        check_all.setOnClickListener(this);    }    @Override    public void onClick(View view) {        switch (view.getId()){            case R.id.check_all:                myAdapter.setIfCheckAll(check_all.isChecked());                break;        }    }    @Override    public void getSuccessCartData(GetCartBean getCartBean) {        //一个是一级标题的数据        List<GetCartBean.DataBean> listGroup = getCartBean.getData();        //所有子条目的数据        List<List<GetCartBean.DataBean.ListBean>> listChilds = new ArrayList<>();        for (int i=0;i<listGroup.size();i++){            listChilds.add(listGroup.get(i).getList());        }        //设置适配器        myAdapter = new MyAdapter(MainActivity.this, listGroup, listChilds,handler);        expanableListview.setAdapter(myAdapter);        //展开所有        for (int i=0;i<listGroup.size();i++){            expanableListview.expandGroup(i);        }    }}
model层:

1.定义接口

public interface ICartModel {    void getSuccessCartJson(String url);}

2.实现接口,请求网络数据

public class CartModel implements ICartModel{    private OnCartListener onCartListener;    public interface OnCartListener{        void onCartListener(GetCartBean getCartBean);    }    public void setOnCartListener(OnCartListener onCartListener){        this.onCartListener = onCartListener;    }    @Override    public void getSuccessCartJson(String url) {        OkHttp3Utils.doGet(url, new GsonObjectCallback<GetCartBean>() {            @Override            public void onUi(GetCartBean getCartBean) {                onCartListener.onCartListener(getCartBean);            }            @Override            public void onFailed(Call call, IOException e) {            }        });    }}

presenter层:逻辑处理

public class CartPresenter implements CartModel.OnCartListener{    private IMainListener iMainListener;    private CartModel cartModel;    public CartPresenter(IMainListener iMainListener) {        this.iMainListener = iMainListener;        this.cartModel = new CartModel();        cartModel.setOnCartListener(this);    }    public void getDataJson(String url){        cartModel.getSuccessCartJson(url);    }    @Override    public void onCartListener(GetCartBean getCartBean) {        iMainListener.getSuccessCartData(getCartBean);    }}

bean类:

public class GetCartBean {    /**     * msg : 请求成功     * code : 0     * data : [{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":22,"price":799,"pscid":1,"selected":0,"sellerid":15,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家15","sellerid":"15"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":1,"price":118,"pscid":1,"selected":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家17","sellerid":"17"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":2,"price":299,"pscid":1,"selected":0,"sellerid":18,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家18","sellerid":"18"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":4,"price":999,"pscid":1,"selected":0,"sellerid":20,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家20","sellerid":"20"}]     */    private String msg;    private String code;    private List<DataBean> data;    public String getMsg() {        return msg;    }    public void setMsg(String msg) {        this.msg = msg;    }    public String getCode() {        return code;    }    public void setCode(String code) {        this.code = code;    }    public List<DataBean> getData() {        return data;    }    public void setData(List<DataBean> data) {        this.data = data;    }    public static class DataBean {        public boolean isGroupChecked() {            return isGroupChecked;        }        public void setGroupChecked(boolean groupChecked) {            isGroupChecked = groupChecked;        }        /**         * list : [{"bargainPrice":111.99,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":22,"price":799,"pscid":1,"selected":0,"sellerid":15,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}]         * sellerName : 商家15         * sellerid : 15         */        private boolean isGroupChecked; 手写,接口中没有        private String sellerName;        private String sellerid;        private List<ListBean> list;        public String getSellerName() {            return sellerName;        }        public void setSellerName(String sellerName) {            this.sellerName = sellerName;        }        public String getSellerid() {            return sellerid;        }        public void setSellerid(String sellerid) {            this.sellerid = sellerid;        }        public List<ListBean> getList() {            return list;        }        public void setList(List<ListBean> list) {            this.list = list;        }        public static class ListBean {            /**             * bargainPrice : 111.99             * createtime : 2017-10-14T21:48:08             * detailUrl : https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends             * images : https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg             * num : 1             * pid : 22             * price : 799.0             * pscid : 1             * selected : 0             * sellerid : 15             * subhead : 每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下             * title : 北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g             */            private double bargainPrice;            private String createtime;            private String detailUrl;            private String images;            private int num;            private int pid;            private double price;            private int pscid;            private int selected;            private int sellerid;            private String subhead;            private String title;            public double getBargainPrice() {                return bargainPrice;            }            public void setBargainPrice(double bargainPrice) {                this.bargainPrice = bargainPrice;            }            public String getCreatetime() {                return createtime;            }            public void setCreatetime(String createtime) {                this.createtime = createtime;            }            public String getDetailUrl() {                return detailUrl;            }            public void setDetailUrl(String detailUrl) {                this.detailUrl = detailUrl;            }            public String getImages() {                return images;            }            public void setImages(String images) {                this.images = images;            }            public int getNum() {                return num;            }            public void setNum(int num) {                this.num = num;            }            public int getPid() {                return pid;            }            public void setPid(int pid) {                this.pid = pid;            }            public double getPrice() {                return price;            }            public void setPrice(double price) {                this.price = price;            }            public int getPscid() {                return pscid;            }            public void setPscid(int pscid) {                this.pscid = pscid;            }            public int getSelected() {                return selected;            }            public void setSelected(int selected) {                this.selected = selected;            }            public int getSellerid() {                return sellerid;            }            public void setSellerid(int sellerid) {                this.sellerid = sellerid;            }            public String getSubhead() {                return subhead;            }            public void setSubhead(String subhead) {                this.subhead = subhead;            }            public String getTitle() {                return title;            }            public void setTitle(String title) {                this.title = title;            }        }    }} 
价格和数量public class PriceAndCount {    private double price;    private int count;    public PriceAndCount(double price, int count) {        this.price = price;        this.count = count;    }    public double getPrice() {        return price;    }    public void setPrice(double price) {        this.price = price;    }    public int getCount() {        return count;    }    public void setCount(int count) {        this.count = count;    }}

adapter:

public class MyAdapter extends BaseExpandableListAdapter {    private Handler handler;    private Context context;    private List<GetCartBean.DataBean> listGroup;    private List<List<GetCartBean.DataBean.ListBean>> listChilds;    public MyAdapter(Context context, List<GetCartBean.DataBean> listGroup, List<List<GetCartBean.DataBean.ListBean>> listChilds, Handler handler) {        this.context = context;        this.listGroup = listGroup;        this.listChilds = listChilds;        this.handler = handler;    }    @Override    public int getGroupCount() {        return listGroup.size();    }    @Override    public int getChildrenCount(int i) {        return listChilds.get(i).size();    }    @Override    public Object getGroup(int i) {        return listGroup.get(i);    }    @Override    public Object getChild(int i, int i1) {        return listChilds.get(i).get(i1);    }    @Override    public long getGroupId(int i) {        return i;    }    @Override    public long getChildId(int i, int i1) {        return i1;    }    @Override    public boolean hasStableIds() {        return true;    }    @Override    public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) {        GroupHolder holder;        if (view == null){            view = View.inflate(context, R.layout.group_item_layout,null);            holder = new GroupHolder();            holder.check_group = view.findViewById(R.id.check_group);            holder.text_group = view.findViewById(R.id.text_group);            view.setTag(holder);        }else {            holder = (GroupHolder) view.getTag();        }        final GetCartBean.DataBean dataBean = listGroup.get(i);        //赋值        holder.check_group.setChecked(dataBean.isGroupChecked());        holder.text_group.setText(dataBean.getSellerName());        //设置点击事件        holder.check_group.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                //2.1改变当前一级选中的状态                dataBean.setGroupChecked(! dataBean.isGroupChecked());                //2.2根据当前一级的状态,改变该组里面二级列表的状态                changeChildState(i,dataBean.isGroupChecked());                //2.3通过判断所有的一级组是否选中,来决定是否全选选中                changeAllState(isAllGroupChecked());                //2.4发送价格个数量:                sendPriceAndCount();                //刷新适配器                notifyDataSetChanged();            }        });        return view;    }    private void changeAllState(boolean allGroupChecked) {        Message msg = Message.obtain();        msg.what =1;        msg.obj = allGroupChecked;        handler.sendMessage(msg);    }    private boolean isAllGroupChecked() {        for (int i=0;i<listGroup.size();i++){            if (! listGroup.get(i).isGroupChecked()){                return false;            }        }        return true;    }    private void changeChildState(int groupPosition, boolean groupChecked) {        List<GetCartBean.DataBean.ListBean> listBeans = listChilds.get(groupPosition);        for (int i=0;i<listBeans.size();i++){            listBeans.get(i).setSelected(groupChecked? 1:0);        }    }    @Override    public View getChildView(final int i, int i1, boolean b, View view, ViewGroup viewGroup) {        ChildHolder holder;        if (view == null){            view = View.inflate(context, R.layout.child_item_layout,null);            holder = new ChildHolder();            holder.text_add = view.findViewById(R.id.text_add);            holder.text_num = view.findViewById(R.id.text_num);            holder.text_jian = view.findViewById(R.id.text_jian);            holder.text_title = view.findViewById(R.id.text_title);            holder.text_price = view.findViewById(R.id.text_price);            holder.image_good = view.findViewById(R.id.image_good);            holder.check_child = view.findViewById(R.id.check_child);            view.setTag(holder);        }else {            holder = (ChildHolder) view.getTag();        }        //赋值        final GetCartBean.DataBean.ListBean listBean = listChilds.get(i).get(i1);        holder.text_num.setText(listBean.getNum()+"");//......注意        holder.text_price.setText("¥"+listBean.getPrice());        holder.text_title.setText(listBean.getTitle());        //listBean.getSelected().....0false,,,1true        //设置checkBox选中状态        holder.check_child.setChecked(listBean.getSelected()==0? false:true);        /*implementation 'com.github.bumptech.glide:glide:4.4.0'        annotationProcessor 'com.github.bumptech.glide:compiler:4.4.0'*/        Glide.with(context).load(listBean.getImages().split("\\|")[0]).into(holder.image_good);        //设置点击事件        holder.check_child.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                //3.1点击改变当前子条目状态:....实际是改变当前的数据,,,刷新适配器                listBean.setSelected(listBean.getSelected() ==0? 1:0);                //3.2发送价钱和数量给界面显示                sendPriceAndCount();                //3.3判断当前子条目是否选中                if (listBean.getSelected() == 1){                    //判断一下当前组中所有的子条目是否全部选中                    if (isAllChildSelected(i)){                        //如果全部选中改变一下当前组的状态                        changeGroupState(i,true);                        //.确定是否改变全选                        changeAllState(isAllGroupChecked());                    }                }else {                    //如果没有选中改变一下当前组的状态                    changeGroupState(i,false);                    //.确定是否改变全选                    changeAllState(isAllGroupChecked());                }                //刷新适配器                notifyDataSetChanged();            }        });        //加号:        holder.text_add.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                //改变当前位置 中商品的数量                listBean.setNum(listBean.getNum()+1);                //判断一下是否选中...计算价格数量                if (listBean.getSelected() == 1){                    sendPriceAndCount();                }                //                notifyDataSetChanged();            }        });        //减号        holder.text_jian.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                int num = listBean.getNum();                if (num == 1){                    return;                }                listBean.setNum(num -1);                //判断是否选中                if (listBean.getSelected() == 1){                    sendPriceAndCount();                }                notifyDataSetChanged();            }        });        return view;    }    private void changeGroupState(int groupPosition, boolean b) {        listGroup.get(groupPosition).setGroupChecked(b);    }    private boolean isAllChildSelected(int groupPosition) {        List<GetCartBean.DataBean.ListBean> listBeans = listChilds.get(groupPosition);        for (int i=0;i<listBeans.size();i++){            if (listBeans.get(i).getSelected() == 0){                return false;            }        }        return true;    }    @Override    public boolean isChildSelectable(int i, int i1) {        return true;    }    public void setIfCheckAll(boolean checked) {        for (int i = 0;i<listGroup.size();i++){            GetCartBean.DataBean dataBean = listGroup.get(i);            //设置组上面的checkBox是否选中            dataBean.setGroupChecked(checked);            List<GetCartBean.DataBean.ListBean> listBeans = dataBean.getList();            for (int j = 0; j< listBeans.size(); j++){                //改变是否选中的状态...数据应该变的是                listBeans.get(j).setSelected(checked? 1:0);            }        }        //计算价钱和数量并且发送到mainActivity显示        sendPriceAndCount();        //刷新适配器        notifyDataSetChanged();    }    private void sendPriceAndCount() {        double price = 0;        int count = 0;        for (int i=0;i<listGroup.size();i++){            List<GetCartBean.DataBean.ListBean> listBeans = listGroup.get(i).getList();            for (int j = 0;j<listBeans.size();j++){                GetCartBean.DataBean.ListBean listBean = listBeans.get(j);                if (listBean.getSelected()==1){                    price += listBean.getPrice()* listBean.getNum();                    count += listBean.getNum();                }            }        }        PriceAndCount countPriceBean = new PriceAndCount(price, count);        //显示到activity页面        Message msg = Message.obtain();        msg.what = 0;        msg.obj = countPriceBean;        handler.sendMessage(msg);    }    private class GroupHolder{        CheckBox check_group;        TextView text_group;    }    private class ChildHolder{        CheckBox check_child;        ImageView image_good;        TextView text_title;        TextView text_price;        TextView text_jian;        TextView text_num;        TextView text_add;    }}
activity_main.xml

<RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="com.bwie.fanmeihua.shoppingcart.MainActivity">    <ScrollView        android:layout_above="@+id/linear_layout"        android:layout_width="match_parent"        android:layout_height="match_parent">        <LinearLayout            android:orientation="vertical"            android:layout_width="match_parent"            android:layout_height="match_parent">            <!--购物车的二级列表-->            <com.bwie.fanmeihua.shoppingcart.view.CartExpanableListview                android:id="@+id/expanable_listview"                android:layout_width="match_parent"                android:layout_height="wrap_content">            </com.bwie.fanmeihua.shoppingcart.view.CartExpanableListview>            <!--为你推荐-->            <LinearLayout                android:orientation="vertical"                android:layout_width="match_parent"                android:layout_height="500dp">            </LinearLayout>        </LinearLayout>    </ScrollView>    <LinearLayout        android:id="@+id/linear_layout"        android:layout_alignParentBottom="true"        android:gravity="center_vertical"        android:orientation="horizontal"        android:layout_width="match_parent"        android:layout_height="50dp">        <CheckBox            android:layout_marginLeft="10dp"            android:button="@null"            android:background="@drawable/check_box_selector"            android:id="@+id/check_all"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />        <TextView            android:id="@+id/text_total"            android:text="合计:¥0.00"            android:layout_weight="2"            android:layout_width="0dp"            android:layout_height="wrap_content" />        <TextView            android:text="去结算(0)"            android:background="#ff0000"            android:textColor="#ffffff"            android:gravity="center"            android:id="@+id/text_buy"            android:layout_width="0dp"            android:layout_weight="1"            android:layout_height="match_parent" />    </LinearLayout></RelativeLayout>

child_item.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:padding="10dp"    android:layout_width="match_parent"    android:layout_height="match_parent">    <CheckBox        android:layout_centerVertical="true"        android:id="@+id/check_child"        android:button="@null"        android:background="@drawable/check_box_selector"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <ImageView        android:id="@+id/image_good"        android:layout_centerVertical="true"        android:layout_toRightOf="@+id/check_child"        android:layout_marginLeft="10dp"        android:layout_width="80dp"        android:layout_height="80dp" />    <TextView        android:id="@+id/text_title"        android:layout_toRightOf="@+id/image_good"        android:layout_marginLeft="10dp"        android:layout_alignTop="@+id/image_good"        android:maxLines="2"        android:minLines="2"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <TextView        android:id="@+id/text_price"        android:layout_toRightOf="@+id/image_good"        android:layout_marginLeft="10dp"        android:layout_alignBottom="@+id/image_good"        android:text="¥99.99"        android:textColor="#ff0000"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <LinearLayout        android:orientation="horizontal"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignBottom="@+id/text_price"        android:layout_alignParentRight="true"        android:layout_alignParentEnd="true">        <TextView            android:id="@+id/text_jian"            android:text="一"            android:padding="5dp"            android:background="@drawable/bian_kuang_line"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />        <TextView            android:gravity="center"            android:id="@+id/text_num"            android:paddingLeft="10dp"            android:paddingRight="10dp"            android:background="@drawable/bian_kuang_line"            android:layout_width="wrap_content"            android:layout_height="match_parent" />        <TextView            android:id="@+id/text_add"            android:text="十"            android:padding="5dp"            android:background="@drawable/bian_kuang_line"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />    </LinearLayout></RelativeLayout>

group_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="horizontal"    android:gravity="center_vertical"    android:padding="10dp"    android:layout_width="match_parent"    android:layout_height="match_parent">    <CheckBox        android:button="@null"        android:background="@drawable/check_box_selector"        android:id="@+id/check_group"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <TextView        android:layout_marginLeft="10dp"        android:text="京东自营"        android:id="@+id/text_group"        android:layout_width="wrap_content"        android:layout_height="wrap_content" /></LinearLayout>


原创粉丝点击