简单的购物车实现



本片文章主要是简单实现购物车

所以其中的数据是假数据,其中的图片和选择器都可以替换,只是简单实现一下

使用二级列表实现的 

主要的逻辑就是在适配器


首先看一下数据源GoodBean

package bwie.com.test;

import java.util.List;

public class GoodBean {

    private List<ContentBean> content;
    private int allMoney;
    private int allCount;
    private boolean isAllSelect;

    public boolean isAllSelect() {
        return isAllSelect;
    }

    public void setAllSelect(boolean allSelect) {
        isAllSelect = allSelect;
    }

    public int getAllMoney() {
        return allMoney;
    }

    public void setAllMoney(int allMoney) {
        this.allMoney = allMoney;
    }

    public int getAllCount() {
        return allCount;
    }

    public void setAllCount(int allCount) {
        this.allCount = allCount;
    }

    public List<ContentBean> getContent() {
        return content;
    }

    public void setContent(List<ContentBean> content) {
        this.content = content;
    }

    public static class ContentBean {
        private String id;
        private String address;
        private boolean isSelected;

        private List<GoodDetailBean> goodDetail;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getAddress() {
            return address;
        }

        public void setAdress(String address) {
            this.address = address;
        }

        public boolean isSelected() {
            return isSelected;
        }

        public void setIsSelected(boolean isSelected) {
            this.isSelected = isSelected;
        }

        public List<GoodDetailBean> getGoodDetail() {
            return goodDetail;
        }

        public void setGoodDetail(List<GoodDetailBean> goodDetail) {
            this.goodDetail = goodDetail;
        }

        public static class GoodDetailBean {
            private String id;
            private String pic;
            private String count;
            private String name;
            private String price;
            private boolean isEdit;
            private boolean isSelected;

            public boolean isEdit() {
                return isEdit;
            }

            public boolean isSelected() {
                return isSelected;
            }

            public void setIsSelected(boolean isSelected) {
                this.isSelected = isSelected;
            }

            public String getId() {
                return id;
            }

            public void setId(String id) {
                this.id = id;
            }

            public String getPic() {
                return pic;
            }

            public void setPic(String pic) {
                this.pic = pic;
            }

            public String getCount() {
                return count;
            }

            public void setCount(String count) {
                this.count = count;
            }


            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public String getPrice() {
                return price;
            }

            public void setPrice(String price) {
                this.price = price;
            }

            public boolean isIsedit() {
                return isEdit;
            }

            public void setIsEdit(boolean isEdit) {
                this.isEdit = isEdit;
            }
        }
    }
}


会用到一个接口

package bwie.com.test;

public interface UpdataView {
    void updata(boolean isAllSelected,int count,int price);
}

MainActivity


package bwie.com.test;

import android.app.Activity;
import android.content.res.AssetManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.TextView;

import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


public class MainActivity extends AppCompatActivity implements UpdataView,View.OnClickListener {
    private ExpandableListView expandableListView;
    private SmoothCheckBox cbSelectAll;
    private TextView moneyAll;
    private TextView tvYunfei;
    private Button butFinish;
    StringBuffer stringBuffer;
    private GoodBean goodBean;
    ExpandableListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initData();
        initAll();

    }

    private void initAll() {
        cbSelectAll.setOnClickListener(this);
    }

    private void initData() {

        AssetManager assetManager = getAssets();
        try {
            InputStream inputStream = assetManager.open("data.json");
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            stringBuffer = new StringBuffer();
            String str;
            while((str = br.readLine()) != null){
                stringBuffer.append(str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        Gson gson = new Gson();
        goodBean = gson.fromJson(stringBuffer.toString(),GoodBean.class);

        adapter = new ExpandableListAdapter(this,goodBean);
        adapter.setChangedListener(this);
        expandableListView.setAdapter(adapter);
        //展开所有的分组
        for (int i = 0; i < goodBean.getContent().size(); i++) {
            expandableListView.expandGroup(i);
        }
    }

    private void initView() {

        expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
        cbSelectAll = (SmoothCheckBox) findViewById(R.id.cb_select_all);
        moneyAll = (TextView) findViewById(R.id.money_all);
        tvYunfei = (TextView) findViewById(R.id.tv_yunfei);
        butFinish = (Button) findViewById(R.id.but_finish);

        //去掉二级列表默认的箭头
        expandableListView.setGroupIndicator(null);

        //用于列表滑动时,EditText清除焦点,收起软键盘
        expandableListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {
                    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity
                            .INPUT_METHOD_SERVICE);
                    View focusView = getCurrentFocus();
                    if (focusView != null) {
                        inputMethodManager.hideSoftInputFromWindow(focusView.getWindowToken(), InputMethodManager
                                .HIDE_NOT_ALWAYS);
                        focusView.clearFocus();
                    }
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int i, int i1, int i2) {

            }
        });


    }


    @Override
    public void updata(boolean isAllSelected, int count, int price) {
        butFinish.setText("结算:("+count+")");
        moneyAll.setText("¥"+price);
        cbSelectAll.setChecked(isAllSelected);
    }

    @Override
    public void onClick(View v) {
        selectedAll();
    }

    private void selectedAll() {
        int allCount = goodBean.getAllCount();
        int allMoney = goodBean.getAllMoney();
        if (!cbSelectAll.isChecked()) {
            goodBean.setAllSelect(true);
            for (int i = 0; i < goodBean.getContent().size(); i++) {
                goodBean.getContent().get(i).setIsSelected(true);
                for (int n = 0; n < goodBean.getContent().get(i).getGoodDetail().size(); n++) {
                    if (!goodBean.getContent().get(i).getGoodDetail().get(n).isSelected()) {
                        allCount++;
                        allMoney += Integer.valueOf(goodBean.getContent().get(i).getGoodDetail().get(n).getCount())
                                * Integer.valueOf(goodBean.getContent().get(i).getGoodDetail().get(n).getPrice());
                        goodBean.getContent().get(i).getGoodDetail().get(n).setIsSelected(true);
                    }
                }
            }
        } else {
            goodBean.setAllSelect(false);
            for (int i = 0; i < goodBean.getContent().size(); i++) {
                goodBean.getContent().get(i).setIsSelected(false);
                for (int n = 0; n < goodBean.getContent().get(i).getGoodDetail().size(); n++) {
                    goodBean.getContent().get(i).getGoodDetail().get(n).setIsSelected(false);
                }
                allCount = 0;
                allMoney = 0;
            }
        }
        goodBean.setAllMoney(allMoney);
        goodBean.setAllCount(allCount);
        updata(goodBean.isAllSelect(), allCount, allMoney);
        adapter.notifyDataSetChanged();
    }
}


最后是二级列表的适配器

主要的操作是在这里面


package bwie.com.test;

import android.content.Context;
import android.text.Editable;
import android.text.Layout;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private Context context;
    private GoodBean goodBean;
    private UpdataView updataViewListener;
    protected static final int KEY_DATA = 0xFFF11133;

    public ExpandableListAdapter(Context context, GoodBean goodBean) {
        this.context = context;
        this.goodBean = goodBean;
    }

    @Override
    public int getGroupCount() {
        return goodBean.getContent().size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return goodBean.getContent().get(groupPosition).getGoodDetail().size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return goodBean.getContent().get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return goodBean.getContent().get(groupPosition).getGoodDetail().get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        GroupViewHolder groupViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_shoppingcart_group, parent, false);
            groupViewHolder = new GroupViewHolder(convertView);
            convertView.setTag(groupViewHolder);
        } else {
            groupViewHolder = (GroupViewHolder) convertView.getTag();
        }
        groupViewHolder.cbGroupItem.setTag(groupPosition);
        groupViewHolder.cbGroupItem.setOnClickListener(listener);
        groupViewHolder.tvPosition.setText(goodBean.getContent().get(groupPosition).getAddress());
        //根据获取的状态设置是否被选中
        if (goodBean.getContent().get(groupPosition).isSelected()) {
            if (!groupViewHolder.cbGroupItem.isChecked()) {
                groupViewHolder.cbGroupItem.setChecked(true);
            }
        } else {
            groupViewHolder.cbGroupItem.setChecked(false);
        }
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ChildViewHolder childViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_shoppingcart_child, parent, false);
            childViewHolder = new ChildViewHolder(convertView);
            convertView.setTag(childViewHolder);
        } else {
            childViewHolder = (ChildViewHolder) convertView.getTag();
        }

        String tag = groupPosition + "," + childPosition;
        childViewHolder.cbItem.setTag(tag);
        childViewHolder.tvReduce.setTag(tag);
        childViewHolder.tvAdd.setTag(tag);
        childViewHolder.imgDelete.setTag(tag);
        childViewHolder.imgIcon.setTag(tag);

        childViewHolder.cbItem.setOnClickListener(listener);
        childViewHolder.tvReduce.setOnClickListener(listener);
        childViewHolder.tvAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String tag = v.getTag().toString();
                String[] split;
                int groupId = 0;
                int childId = 0;
                int allCount = goodBean.getAllCount();
                int allMoney;
                if (tag.contains(",")) {
                    split = tag.split(",");
                    groupId = Integer.parseInt(split[0]);
                    childId = Integer.parseInt(split[1]);
                }
                String goodCount = goodBean.getContent().get(groupId).getGoodDetail().get(childId).getCount();
                goodBean.getContent().get(groupId).getGoodDetail().get(childId).setCount(addCount(goodCount));
                allMoney = goodBean.getAllMoney();
                if (goodBean.getContent().get(groupId).getGoodDetail().get(childId).isSelected()) {
                    allMoney += Integer.valueOf(goodBean.getContent().get(groupId).getGoodDetail().get(childId).getPrice());
                    updataViewListener.updata(goodBean.isAllSelect(), allCount, allMoney);
                }
                goodBean.setAllMoney(allMoney);
                notifyDataSetChanged();
            }
        });

        childViewHolder.imgDelete.setOnClickListener(listener);
        //根据获取的状态设置是否被选中
        if (goodBean.getContent().get(groupPosition).getGoodDetail().get(childPosition).isSelected()) {
            childViewHolder.cbItem.setChecked(true);
        } else {
            childViewHolder.cbItem.setChecked(false);
        }
        //设置数据
        childViewHolder.tvPrice.setText("¥" + goodBean.getContent().get(groupPosition).getGoodDetail().get(childPosition).getPrice());
        childViewHolder.tvGoodName.setText(goodBean.getContent().get(groupPosition).getGoodDetail().get(childPosition).getName());
        //对商品数量的监听
        EditTextWatcher textWatcher = (EditTextWatcher) childViewHolder.etCount.getTag(KEY_DATA);
        if (textWatcher != null) {
            childViewHolder.etCount.removeTextChangedListener(textWatcher);
        }
        childViewHolder.etCount.setText(String.valueOf(goodBean.getContent().get(groupPosition).getGoodDetail().get(childPosition).getCount()));
        EditTextWatcher watcher = new EditTextWatcher(goodBean.getContent().get(groupPosition).getGoodDetail().get(childPosition));
        childViewHolder.etCount.setTag(KEY_DATA, watcher);
        childViewHolder.etCount.addTextChangedListener(watcher);

        childViewHolder.etCount.setText(goodBean.getContent().get(groupPosition).getGoodDetail().get(childPosition).getCount());

        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            SmoothCheckBox checkBox;
            String tag = v.getTag().toString();
            String[] split;
            int groupId = 0;
            int childId = 0;
            int childSize = 0;
            int groupPosition = 0;
            int allCount = goodBean.getAllCount();//被选中的item数量
            int allMoney = goodBean.getAllMoney();
            if (tag.contains(",")) {
                split = tag.split(",");
                groupId = Integer.parseInt(split[0]);
                childId = Integer.parseInt(split[1]);
            } else {
                groupPosition = Integer.parseInt(tag);
                childSize = goodBean.getContent().get(groupPosition).getGoodDetail().size();
            }
            switch (v.getId()) {
                case R.id.cb_item_group:
                    checkBox = (SmoothCheckBox) v;
                    //根据父checkbox的选中状态设置存储数据里面商品是否被选中
                    goodBean.getContent().get(groupPosition).setIsSelected(!checkBox.isChecked());
                    if (!checkBox.isChecked()) {
                        for (int i = 0; i < childSize; i++) {
                            if (!goodBean.getContent().get(groupPosition).getGoodDetail().get(i).isSelected()) {
                                allCount++;
                                goodBean.getContent().get(groupPosition).getGoodDetail().get(i).setIsSelected(!checkBox.isChecked());
                                allMoney += Integer.valueOf(goodBean.getContent().get(groupPosition).getGoodDetail().get(i).getCount())
                                        * Integer.valueOf(goodBean.getContent().get(groupPosition).getGoodDetail().get(i).getPrice());
                            }
                        }
                    } else {
                        allCount -= childSize;
                        for (int i = 0; i < childSize; i++) {
                            goodBean.getContent().get(groupPosition).getGoodDetail().get(i).setIsSelected(!checkBox.isChecked());
                            allMoney -= Integer.valueOf(goodBean.getContent().get(groupPosition).getGoodDetail().get(i).getCount())
                                    * Integer.valueOf(goodBean.getContent().get(groupPosition).getGoodDetail().get(i).getPrice());
                        }
                    }
                    //父item选中的数量
                    int fCount = 0;
                    //判断是否所有的父item都被选中,决定全选按钮状态
                    for (int i = 0; i < goodBean.getContent().size(); i++) {
                        if (goodBean.getContent().get(i).isSelected()) {
                            fCount++;
                        }
                    }
                    if (fCount == goodBean.getContent().size()) {
                        goodBean.setAllSelect(true);
                    } else {
                        goodBean.setAllSelect(false);
                    }
                    goodBean.setAllCount(allCount);
                    goodBean.setAllMoney(allMoney);
                    notifyDataSetChanged();
                    updataViewListener.updata(goodBean.isAllSelect(), allCount, allMoney);
                    break;
                //单个子项item被点击
                case R.id.cb_item:
                    checkBox = (SmoothCheckBox) v;
                    int cCount = 0;//子item被选中的数量
                    int fcCount = 0;//父item被选中的数量
                    goodBean.getContent().get(groupId).getGoodDetail().get(childId).setIsSelected(!checkBox.isChecked());
                    //遍历父item所有数据,统计被选中的item数量
                    for (int i = 0; i < goodBean.getContent().get(groupId).getGoodDetail().size(); i++) {
                        if (goodBean.getContent().get(groupId).getGoodDetail().get(i).isSelected()) {
                            cCount++;
                        }
                    }
                    //判断是否所有的子item都被选中,决定父item状态
                    if (cCount == goodBean.getContent().get(groupId).getGoodDetail().size()) {
                        goodBean.getContent().get(groupId).setIsSelected(true);
                    } else {
                        goodBean.getContent().get(groupId).setIsSelected(false);
                    }
                    //判断是否所有的父item都被选中,决定全选按钮状态
                    for (int i = 0; i < goodBean.getContent().size(); i++) {
                        if (goodBean.getContent().get(i).isSelected()) {
                            fcCount++;
                        }
                    }
                    if (fcCount == goodBean.getContent().size()) {
                        goodBean.setAllSelect(true);
                    } else {
                        goodBean.setAllSelect(false);
                    }
                    //判断子item状态,更新结算总商品数和合计Money
                    if (!checkBox.isChecked()) {
                        allCount++;
                        allMoney += Integer.valueOf(goodBean.getContent().get(groupId).getGoodDetail().get(childId).getCount())
                                * Integer.valueOf(goodBean.getContent().get(groupId).getGoodDetail().get(childId).getPrice());
                    } else {
                        allCount--;
                        allMoney -= Integer.valueOf(goodBean.getContent().get(groupId).getGoodDetail().get(childId).getCount())
                                * Integer.valueOf(goodBean.getContent().get(groupId).getGoodDetail().get(childId).getPrice());
                    }
                    goodBean.setAllCount(allCount);
                    goodBean.setAllMoney(allMoney);
                    notifyDataSetChanged();
                    updataViewListener.updata(goodBean.isAllSelect(), allCount, allMoney);
                    break;
                case R.id.tv_reduce:
                    //减少商品数量
                    String goodCount = goodBean.getContent().get(groupId).getGoodDetail().get(childId).getCount();
                    if (Integer.valueOf(goodCount) > 1) {
                        goodBean.getContent().get(groupId).getGoodDetail().get(childId).setCount(reduceCount(goodCount));
                        if (goodBean.getContent().get(groupId).getGoodDetail().get(childId).isSelected()) {
                            allMoney -= Integer.valueOf(goodBean.getContent().get(groupId).getGoodDetail().get(childId).getPrice());
                            updataViewListener.updata(goodBean.isAllSelect(), allCount, allMoney);
                        }
                        goodBean.setAllMoney(allMoney);
                        notifyDataSetChanged();
                    }
                    break;
                case R.id.img_delete:
                    goodBean.getContent().get(groupId).getGoodDetail().remove(childId);
                    if (goodBean.getContent().get(groupId).getGoodDetail().size() == 0) {
                        goodBean.getContent().remove(groupId);
                    }
                    notifyDataSetChanged();
                    break;
            }
        }
    };


    public void setChangedListener(UpdataView listener) {
        if (updataViewListener == null) {
            this.updataViewListener = listener;
        }
    }

    private String addCount(String var) {
        Integer integer = Integer.valueOf(var);
        integer++;
        return integer + "";
    }

    private String reduceCount(String var) {
        Integer integer = Integer.valueOf(var);
        if (integer > 1) {
            integer--;
        }
        return integer + "";
    }

    /**
     * 商品数量EditText内容改变的监听
     */
    class EditTextWatcher implements TextWatcher {

        private GoodBean.ContentBean.GoodDetailBean GoodDetail;

        public EditTextWatcher(GoodBean.ContentBean.GoodDetailBean item) {
            this.GoodDetail = item;
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (!TextUtils.isEmpty(s.toString().trim())) {
                String textNum = s.toString().trim();
                GoodDetail.setCount(textNum);
            }
        }
    }

    static class GroupViewHolder {

        SmoothCheckBox cbGroupItem;
        TextView tvPosition;

        GroupViewHolder(View view) {
            cbGroupItem = view.findViewById(R.id.cb_item_group);
            tvPosition = view.findViewById(R.id.tv_position);
        }
    }

    static class ChildViewHolder {
        SmoothCheckBox cbItem;
        TextView tvPrice, tvGoodName;
        EditText etCount;
        TextView tvReduce;
        TextView tvAdd;
        ImageView imgDelete;
        ImageView imgIcon;

        ChildViewHolder(View view) {
            cbItem = (SmoothCheckBox) view.findViewById(R.id.cb_item);
            tvPrice = (TextView) view.findViewById(R.id.tv_price);
            tvGoodName = (TextView) view.findViewById(R.id.tv_good_name);
            etCount = (EditText) view.findViewById(R.id.et_count);
            tvReduce = (TextView) view.findViewById(R.id.tv_reduce);
            tvAdd = (TextView) view.findViewById(R.id.tv_add);
            imgDelete = (ImageView) view.findViewById(R.id.img_delete);
            imgIcon = (ImageView) view.findViewById(R.id.img_icon);
        }
    }

}


activity_main

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".MainActivity">

    <ExpandableListView
        android:id="@+id/expandableListView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:divider="@null"
        android:scrollbars="none" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/divideLine" />


    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center_vertical">

        <bwie.com.test.SmoothCheckBox
            android:id="@+id/cb_select_all"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_marginLeft="10dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="@string/select_all"
            android:textColor="#333" />

        <RelativeLayout
            android:id="@+id/rel2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">


            <RelativeLayout
                android:layout_marginTop="5dp"
                android:id="@+id/rel"
                android:layout_marginRight="100dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true">

                <TextView
                    android:id="@+id/heji"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="合计"
                    android:textColor="#333"
                    android:textSize="15sp" />

                <TextView
                    android:id="@+id/money_all"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@id/heji"
                    android:text="¥0"
                    android:textColor="#fe3824" />

            </RelativeLayout>

            <TextView
                android:id="@+id/tv_yunfei"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="100dp"
                android:layout_below="@id/rel"
                android:text="运费:¥0" />


            <Button
                android:id="@+id/but_finish"
                android:layout_width="95dp"
                android:text="结算(0)"
                android:background="#fe3824"
                android:layout_centerVertical="true"
                android:layout_alignParentRight="true"
                android:layout_height="wrap_content" />
        </RelativeLayout>


    </LinearLayout>


</LinearLayout>

item_shoppingcart_group

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@color/divideLine"
        />

    <LinearLayout
        android:padding="15dp"
        android:gravity="center_vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        
        <bwie.com.test.SmoothCheckBox
            android:id="@+id/cb_item_group"
            android:layout_width="25dp"
            android:layout_height="25dp" />

        <TextView
            android:id="@+id/tv_position"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:drawableLeft="@drawable/ic_position"
            android:drawablePadding="3dp"
            android:text="京东旗舰店发货"
            android:textColor="#333333"
            android:textSize="15sp" />


        
    </LinearLayout>

</LinearLayout>

item_shoppingcart_child

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:paddingBottom="15dp"
    android:paddingRight="15dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/ll_check"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center"
        android:paddingLeft="15dp"
        android:paddingRight="17dp">

        <bwie.com.test.SmoothCheckBox
            android:id="@+id/cb_item"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_gravity="center_vertical" />
    </LinearLayout>

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

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/divideLine" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/img_icon"
                android:layout_width="78dp"
                android:layout_height="78dp"
                android:src="@drawable/ic_phone" />

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="8dp"
                android:layout_weight="1">

                <TextView
                    android:id="@+id/tv_good_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="KKKKKKK" />

                <TextView
                    android:id="@+id/tv_reduce"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_below="@id/tv_good_name"
                    android:layout_marginTop="6dp"
                    android:background="@drawable/selector_shopping_cart_subtract"
                    android:gravity="center"
                    android:text="-"
                    android:textColor="@color/text_666666"
                    android:textSize="15sp" />

                <EditText
                    android:id="@+id/et_count"
                    android:layout_width="49dp"
                    android:layout_height="30dp"
                    android:layout_alignTop="@+id/tv_reduce"
                    android:layout_marginBottom="1dp"
                    android:layout_toRightOf="@+id/tv_reduce"
                    android:background="@drawable/bg_input_box"
                    android:gravity="center"
                    android:inputType="number"
                    android:maxLength="6"
                    android:text="1"
                    android:textColor="@color/text_666666"
                    android:textCursorDrawable="@null"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/tv_add"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_alignTop="@+id/tv_reduce"
                    android:layout_toRightOf="@id/et_count"
                    android:background="@drawable/selector_shopping_cart_add"
                    android:gravity="center"
                    android:text="+"
                    android:textColor="@color/text_666666"
                    android:textSize="15sp" />

                <TextView
                    android:id="@+id/tv_price"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:text="¥899"
                    android:textColor="#FE3824"
                    android:textSize="13sp" />
            </RelativeLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="18dp"
                android:gravity="end"
                android:orientation="vertical">

            </LinearLayout>

            <ImageView
                android:id="@+id/img_delete"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginTop="5dp"
                android:src="@drawable/icon_delete" />

        </LinearLayout>
    </LinearLayout>

</LinearLayout>





猜你喜欢

转载自blog.csdn.net/melect/article/details/80159520