购物车全选,反选,结算

来源:互联网 发布:海信淘宝旗舰店 编辑:程序博客网 时间:2024/06/05 11:52

      购物车全选,反选,结算



使用的一些图标



下面就写代码吧吐舌头


 MainActivity 

package com.love.taobao.activity;import android.graphics.drawable.Drawable;import android.os.Bundle;import android.support.v7.app.ActionBar;import android.support.v7.app.AppCompatActivity;import android.support.v7.widget.LinearLayoutManager;import android.support.v7.widget.RecyclerView;import android.view.View;import android.widget.LinearLayout;import android.widget.RelativeLayout;import android.widget.TextView;import com.love.taobao.R;import com.love.taobao.adapter.ShopCartAdapter;import com.love.taobao.bean.ShopCartBean;import java.util.ArrayList;import java.util.List;/** * http://www.jianshu.com/p/6c3328f87fc9 用的此链接方法实现 */public class MainActivity extends AppCompatActivity {    private TextView tvShopCartSubmit,tvShopCartSelect,tvShopCartTotalNum;    private View mEmtryView;    private RecyclerView rlvShopCart,rlvHotProducts;    private ShopCartAdapter mShopCartAdapter;    private LinearLayout llPay;    private RelativeLayout rlHaveProduct;    private List<ShopCartBean.CartlistBean> mAllOrderList = new ArrayList<>();    private ArrayList<ShopCartBean.CartlistBean> mGoPayList = new ArrayList<>();    private List<String> mHotProductsList = new ArrayList<>();    private TextView tvShopCartTotalPrice;    private int mCount,mPosition;    private float mTotalPrice1;    private boolean mSelect;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_sy_head__xx_);        //隐藏标题        ActionBar actionBar=getSupportActionBar();        actionBar.hide();        //找控件        tvShopCartSelect = (TextView) findViewById(R.id.tv_shopcart_addselect);        tvShopCartTotalPrice = (TextView) findViewById(R.id.tv_shopcart_totalprice);        tvShopCartTotalNum = (TextView) findViewById(R.id.tv_shopcart_totalnum);        rlHaveProduct = (RelativeLayout) findViewById(R.id.rl_shopcart_have);        rlvShopCart = (RecyclerView) findViewById(R.id.rlv_shopcart);        mEmtryView = (View) findViewById(R.id.emtryview);        mEmtryView.setVisibility(View.GONE);        llPay = (LinearLayout) findViewById(R.id.ll_pay);        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);        lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.TRUE);        llPay.setLayoutParams(lp);        tvShopCartSubmit = (TextView) findViewById(R.id.tv_shopcart_submit);        rlvShopCart.setLayoutManager(new LinearLayoutManager(this));        mShopCartAdapter = new ShopCartAdapter(this,mAllOrderList);        rlvShopCart.setAdapter(mShopCartAdapter);        //删除商品接口        mShopCartAdapter.setOnDeleteClickListener(new ShopCartAdapter.OnDeleteClickListener() {            @Override            public void onDeleteClick(View view, int position,int cartid) {                mShopCartAdapter.notifyDataSetChanged();            }        });        //修改数量接口        mShopCartAdapter.setOnEditClickListener(new ShopCartAdapter.OnEditClickListener() {            @Override            public void onEditClick(int position, int cartid, int count) {                mCount = count;                mPosition = position;            }        });        //实时监控全选按钮        mShopCartAdapter.setResfreshListener(new ShopCartAdapter.OnResfreshListener() {            @Override            public void onResfresh( boolean isSelect) {                mSelect = isSelect;                if(isSelect){                    Drawable left = getResources().getDrawable(R.drawable.shopcart_selected);                    tvShopCartSelect.setCompoundDrawablesWithIntrinsicBounds(left,null,null,null);                }else {                    Drawable left = getResources().getDrawable(R.drawable.shopcart_unselected);                    tvShopCartSelect.setCompoundDrawablesWithIntrinsicBounds(left,null,null,null);                }                float mTotalPrice = 0;                int mTotalNum = 0;                mTotalPrice1 = 0;                mGoPayList.clear();                for(int i = 0;i < mAllOrderList.size(); i++)                    if(mAllOrderList.get(i).getIsSelect()) {                        mTotalPrice += Float.parseFloat(mAllOrderList.get(i).getPrice()) * mAllOrderList.get(i).getCount();                        mTotalNum += 1;                        mGoPayList.add(mAllOrderList.get(i));                    }                mTotalPrice1 = mTotalPrice;                tvShopCartTotalPrice.setText("总价:" + mTotalPrice);                tvShopCartTotalNum.setText("共" + mTotalNum + "件商品");            }        });        //全选        tvShopCartSelect.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                mSelect = !mSelect;                if(mSelect){                    Drawable left = getResources().getDrawable(R.drawable.shopcart_selected);                    tvShopCartSelect.setCompoundDrawablesWithIntrinsicBounds(left,null,null,null);                    for(int i = 0;i < mAllOrderList.size();i++){                        mAllOrderList.get(i).setSelect(true);                        mAllOrderList.get(i).setShopSelect(true);                    }                }else{                    Drawable left = getResources().getDrawable(R.drawable.shopcart_unselected);                    tvShopCartSelect.setCompoundDrawablesWithIntrinsicBounds(left,null,null,null);                    for(int i = 0;i < mAllOrderList.size();i++){                        mAllOrderList.get(i).setSelect(false);                        mAllOrderList.get(i).setShopSelect(false);                    }                }                mShopCartAdapter.notifyDataSetChanged();            }        });        initData();        mShopCartAdapter.notifyDataSetChanged();    }    private void initData(){        for(int i = 0;i < 2;i ++){            ShopCartBean.CartlistBean sb = new ShopCartBean.CartlistBean();            sb.setShopId(1);            sb.setPrice("66.8");            sb.setDefaultPic("https://s10.mogucdn.com/mlcdn/c45406/170829_2ff92276gai6icg1jgfjidl0f7b00_778x440.jpg");            sb.setProductName("达人购服饰");            sb.setShopName("精品女装");            sb.setColor("蓝色");            sb.setCount(2);            mAllOrderList.add(sb);        }        for(int i = 0;i < 2;i ++){            ShopCartBean.CartlistBean sb = new ShopCartBean.CartlistBean();            sb.setShopId(2);            sb.setPrice("88.6");            sb.setDefaultPic("https://s10.mogucdn.com/mlcdn/c45406/170831_479g0ifl6f2i313feb5ech46kek21_778x440.jpg");           // sb.setDefaultPic("http://img2.3lian.com/2014/c7/25/d/40.jpg");            sb.setProductName("伊诺儿服饰");            sb.setShopName("伊诺儿");            sb.setColor("粉色");            sb.setCount(2);            mAllOrderList.add(sb);        }        isSelectFirst(mAllOrderList);    }    public static void isSelectFirst(List<ShopCartBean.CartlistBean> list){        if(list.size() > 0) {            list.get(0).setIsFirst(1);            for (int i = 1; i < list.size(); i++) {                if (list.get(i).getShopId() == list.get(i - 1).getShopId()) {                    list.get(i).setIsFirst(2);                } else {                    list.get(i).setIsFirst(1);                }            }        }    }} 
适配器  

package com.love.taobao.adapter;import android.content.Context;import android.support.v7.widget.RecyclerView;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.TextView;import com.love.taobao.R;import com.love.taobao.activity.SY_head_XX_Activity;import com.love.taobao.bean.ShopCartBean;import com.nostra13.universalimageloader.core.ImageLoader;import java.util.List;/** * 
 *ShopCartAdapter适配器
*/
 public class ShopCartAdapter extends RecyclerView.Adapter<ShopCartAdapter.MyViewHolder> {    //String path="http://img2.3lian.com/2014/c7/25/d/40.jpg";   String path="https://s10.mogucdn.com/mlcdn/c45406/170829_2ff92276gai6icg1jgfjidl0f7b00_778x440.jpg";    private Context context;    private List<ShopCartBean.CartlistBean> data;    private View headerView;    private OnDeleteClickListener mOnDeleteClickListener;    private OnEditClickListener mOnEditClickListener;    private OnResfreshListener mOnResfreshListener;    public ShopCartAdapter(Context context, List<ShopCartBean.CartlistBean> data){        this.context = context;        this.data = data;    }    @Override    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {        View view;        view = LayoutInflater.from(context).inflate(R.layout.item_shopcart, parent, false);        return new MyViewHolder(view);    }    @Override    public void onBindViewHolder(final MyViewHolder holder, final int position) {      //  Glide.with(context).load(data.get(position).getDefaultPic()).into(holder.ivShopCartClothPic);        if (position > 0) {            if (data.get(position).getShopId() == data.get(position - 1).getShopId()) {                holder.llShopCartHeader.setVisibility(View.GONE);            } else {                holder.llShopCartHeader.setVisibility(View.VISIBLE);            }        }else {            holder.llShopCartHeader.setVisibility(View.VISIBLE);        }        holder.tvShopCartClothColor.setText("颜色:" + data.get(position).getColor());        holder.tvShopCartClothSize.setText("尺寸:" + data.get(position).getSize());        holder.tvShopCartClothName.setText(data.get(position).getProductName());        holder.tvShopCartShopName.setText(data.get(position).getShopName());        holder.tvShopCartClothPrice.setText("¥" + data.get(position).getPrice());        holder.etShopCartClothNum.setText(data.get(position).getCount() + "");        //加载图片        ImageLoader.getInstance().displayImage(path,holder.ivShopCartClothPic);        if(mOnResfreshListener != null){            boolean isSelect = false;            for(int i = 0;i < data.size(); i++){                if(!data.get(i).getIsSelect()){                    isSelect = false;                    break;                }else{                    isSelect = true;                }            }            mOnResfreshListener.onResfresh(isSelect);        }        holder.ivShopCartClothMinus.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                if(data.get(position).getCount() > 1) {                    int count = data.get(position).getCount() - 1;                    if (mOnEditClickListener != null) {                        mOnEditClickListener.onEditClick(position, data.get(position).getId(), count);                    }                    data.get(position).setCount(count);                    notifyDataSetChanged();                }            }        });        holder.ivShopCartClothAdd.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                int count = data.get(position).getCount() + 1;                if(mOnEditClickListener != null){                    mOnEditClickListener.onEditClick(position,data.get(position).getId(),count);                }                data.get(position).setCount(count);                notifyDataSetChanged();            }        });        if(data.get(position).getIsSelect()){            holder.ivShopCartClothSel.setImageDrawable(context.getResources().getDrawable(R.drawable.shopcart_selected));        }else {            holder.ivShopCartClothSel.setImageDrawable(context.getResources().getDrawable(R.drawable.shopcart_unselected));        }        if(data.get(position).getIsShopSelect()){            holder.ivShopCartShopSel.setImageDrawable(context.getResources().getDrawable(R.drawable.shopcart_selected));        }else {            holder.ivShopCartShopSel.setImageDrawable(context.getResources().getDrawable(R.drawable.shopcart_unselected));        }        holder.ivShopCartClothDelete.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                showDialog(v,position);            }        });        holder.ivShopCartClothSel.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                data.get(position).setSelect(!data.get(position).getIsSelect());                //通过循环找出不同商铺的第一个商品的位置                for(int i = 0;i < data.size(); i++){                    if(data.get(i).getIsFirst() == 1) {                        //遍历去找出同一家商铺的所有商品的勾选情况                        for(int j = 0;j < data.size();j++){                            //如果是同一家商铺的商品,并且其中一个商品是未选中,那么商铺的全选勾选取消                            if(data.get(j).getShopId() == data.get(i).getShopId() && !data.get(j).getIsSelect()){                                data.get(i).setShopSelect(false);                                break;                            }else{                                //如果是同一家商铺的商品,并且所有商品是选中,那么商铺的选中全选勾选                                data.get(i).setShopSelect(true);                            }                        }                    }                }                notifyDataSetChanged();            }        });        holder.ivShopCartShopSel.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                if(data.get(position).getIsFirst() == 1) {                    data.get(position).setShopSelect(!data.get(position).getIsShopSelect());                    for(int i = 0;i < data.size();i++){                        if(data.get(i).getShopId() == data.get(position).getShopId()){                            data.get(i).setSelect(data.get(position).getIsShopSelect());                        }                    }                    notifyDataSetChanged();                }            }        });    }    private void showDialog(final View view, final int position){            //调用删除某个规格商品的接口            if(mOnDeleteClickListener != null){                mOnDeleteClickListener.onDeleteClick(view,position,data.get(position).getId());            }            data.remove(position);            //重新排序,标记所有商品不同商铺第一个的商品位置    SY_head_XX_Activity.isSelectFirst(data);            notifyDataSetChanged();    }    @Override    public int getItemCount() {        int count = (data == null ? 0 : data.size());        if(headerView != null){            count++;        }        return count;    }    class MyViewHolder extends RecyclerView.ViewHolder    {        private ImageView ivShopCartShopSel;        private TextView tvShopCartShopName;        private TextView tvShopCartClothName;        private TextView tvShopCartClothPrice;        private TextView etShopCartClothNum;        private TextView tvShopCartClothColor;        private TextView tvShopCartClothSize;        private ImageView ivShopCartClothSel;        private ImageView ivShopCartClothMinus;        private ImageView ivShopCartClothAdd;        private ImageView ivShopCartClothDelete;        private ImageView ivShopCartClothPic;        private LinearLayout llShopCartHeader;        public MyViewHolder(View view)        {            super(view);            llShopCartHeader = (LinearLayout) view.findViewById(R.id.ll_shopcart_header);            ivShopCartShopSel = (ImageView) view.findViewById(R.id.iv_item_shopcart_shopselect);            tvShopCartShopName = (TextView) view.findViewById(R.id.tv_item_shopcart_shopname);            tvShopCartClothName = (TextView) view.findViewById(R.id.tv_item_shopcart_clothname);            tvShopCartClothPrice = (TextView) view.findViewById(R.id.tv_item_shopcart_cloth_price);            etShopCartClothNum = (TextView) view.findViewById(R.id.et_item_shopcart_cloth_num);            tvShopCartClothColor = (TextView) view.findViewById(R.id.tv_item_shopcart_cloth_color);            tvShopCartClothSize = (TextView) view.findViewById(R.id.tv_item_shopcart_cloth_size);            ivShopCartClothSel = (ImageView) view.findViewById(R.id.tv_item_shopcart_clothselect);            ivShopCartClothMinus = (ImageView) view.findViewById(R.id.iv_item_shopcart_cloth_minus);            ivShopCartClothAdd = (ImageView) view.findViewById(R.id.iv_item_shopcart_cloth_add);            ivShopCartClothPic = (ImageView) view.findViewById(R.id.iv_item_shopcart_cloth_pic);            ivShopCartClothDelete = (ImageView) view.findViewById(R.id.iv_item_shopcart_cloth_delete);        }    }    public View getHeaderView(){        return headerView;    }    private OnItemClickListener mOnItemClickListener;    public interface OnItemClickListener{        void onItemClick(View view, int position);    }    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener){        this.mOnItemClickListener = mOnItemClickListener;    }    public interface OnDeleteClickListener{        void onDeleteClick(View view, int position, int cartid);    }    public void setOnDeleteClickListener(OnDeleteClickListener mOnDeleteClickListener){        this.mOnDeleteClickListener = mOnDeleteClickListener;    }    public interface OnEditClickListener{        void onEditClick(int position, int cartid, int count);    }    public void setOnEditClickListener(OnEditClickListener mOnEditClickListener){        this.mOnEditClickListener = mOnEditClickListener;    }    public interface OnResfreshListener{        void onResfresh(boolean isSelect);    }    public void setResfreshListener(OnResfreshListener mOnResfreshListener){        this.mOnResfreshListener = mOnResfreshListener;    }}

Bean类
package com.love.taobao.bean;import java.util.List;/** * Created by Administrator on 2016/10/14. */public class ShopCartBean {    /**     * shopId : 2     * shopName : null     * cartlist : [{"id":2,"shopId":2,"shopName":null,"productId":2,"productName":null,"color":null,"size":null,"price":null,"count":null}]     */    private int shopId;    private Object shopName;    /**     * id : 2     * shopId : 2     * shopName : null     * productId : 2     * productName : null     * color : null     * size : null     * price : null     * count : null     */    private List<CartlistBean> cartlist;    public int getShopId() {        return shopId;    }    public void setShopId(int shopId) {        this.shopId = shopId;    }    public Object getShopName() {        return shopName;    }    public void setShopName(Object shopName) {        this.shopName = shopName;    }    public List<CartlistBean> getCartlist() {        return cartlist;    }    public void setCartlist(List<CartlistBean> cartlist) {        this.cartlist = cartlist;    }    public static class CartlistBean {        private int id;        private int shopId;        private String shopName;        private int productId;        private String productName;        private String color;        private String size;        private String price;        private String defaultPic;        private int count;        private boolean isSelect = true;        private int isFirst = 2;        private boolean isShopSelect = true;        public String getDefaultPic() {            return defaultPic;        }        public void setDefaultPic(String defaultPic) {            this.defaultPic = defaultPic;        }        public boolean getIsShopSelect() {            return isShopSelect;        }        public void setShopSelect(boolean shopSelect) {            isShopSelect = shopSelect;        }        public int getIsFirst() {            return isFirst;        }        public void setIsFirst(int isFirst) {            this.isFirst = isFirst;        }        public boolean getIsSelect() {            return isSelect;        }        public void setSelect(boolean select) {            isSelect = select;        }        public int getId() {            return id;        }        public void setId(int id) {            this.id = id;        }        public int getShopId() {            return shopId;        }        public void setShopId(int shopId) {            this.shopId = shopId;        }        public String getShopName() {            return shopName;        }        public void setShopName(String shopName) {            this.shopName = shopName;        }        public int getProductId() {            return productId;        }        public void setProductId(int productId) {            this.productId = productId;        }        public String getProductName() {            return productName;        }        public void setProductName(String productName) {            this.productName = productName;        }        public String getColor() {            return color;        }        public void setColor(String color) {            this.color = color;        }        public String getSize() {            return size;        }        public void setSize(String size) {            this.size = size;        }        public String getPrice() {            return price;        }        public void setPrice(String price) {            this.price = price;        }        public int getCount() {            return count;        }        public void setCount(int count) {            this.count = count;        }    }}

head布局

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:background="@android:color/holo_orange_light"    android:layout_height="40dp"    >    <TextView        android:id="@+id/log_iv1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="返回"        android:layout_margin="10dp"        android:textColor="@android:color/holo_red_light"        />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="购物车"      android:layout_centerHorizontal="true"        android:layout_marginTop="5dp"        android:textSize="20dp"        android:textColor="@android:color/holo_red_light"        />    <TextView        android:id="@+id/log_tv1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="编辑"        android:layout_margin="10dp"        android:layout_alignParentRight="true"        android:textColor="@android:color/holo_red_light"        android:textSize="15sp"        /></RelativeLayout>



MainActivity布局

<?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:orientation="vertical"    android:background="#FFE4E1"    >    <include       layout="@layout/gouwu_head"        ></include>    <RelativeLayout        android:id="@+id/rl_shopcart_have"        android:layout_width="match_parent"        android:layout_height="match_parent">        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="vertical"            >            <android.support.v7.widget.RecyclerView                android:id="@+id/rlv_shopcart"                android:layout_width="match_parent"                android:layout_height="0dp"                android:layout_weight="1"                ></android.support.v7.widget.RecyclerView>            <View                android:layout_width="match_parent"                android:layout_height="50dp">            </View>        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal"            android:background="@android:color/white"            android:gravity="center_vertical"            android:id="@+id/ll_pay"            android:layout_above="@+id/emtryview"            >            <TextView                android:id="@+id/tv_shopcart_addselect"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginLeft="@dimen/margin_10dp"                android:drawableLeft="@drawable/shopcart_selected"                android:text="全选"                android:drawablePadding="@dimen/padding_5dp"                />            <LinearLayout                android:layout_width="0dp"                android:layout_height="wrap_content"                android:layout_weight="1"                android:orientation="vertical"                >                <TextView                    android:id="@+id/tv_shopcart_totalprice"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:paddingLeft="@dimen/padding_10dp"                    android:paddingTop="@dimen/padding_10dp"                    android:text="总价:¥0"                    android:textColor="@android:color/holo_red_light"                    android:textSize="16sp"                    />                <TextView                    android:id="@+id/tv_shopcart_totalnum"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:paddingLeft="@dimen/padding_10dp"                    android:text="共0件商品"                    android:textSize="14sp"                    android:paddingBottom="@dimen/padding_10dp"                    />            </LinearLayout>            <TextView                android:id="@+id/tv_shopcart_submit"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@drawable/login_btn"                android:text="去结算"                android:paddingLeft="@dimen/margin_30dp"                android:paddingRight="@dimen/margin_30dp"                android:paddingTop="@dimen/padding_10dp"                android:paddingBottom="@dimen/padding_10dp"                android:textColor="@android:color/white"                android:layout_marginRight="@dimen/margin_10dp"                />        </LinearLayout>        <View            android:id="@+id/emtryview"            android:layout_width="match_parent"            android:layout_alignParentBottom="true"            android:layout_height="10dp">        </View>    </RelativeLayout></LinearLayout>
item

 

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="vertical"    >    <LinearLayout        android:id="@+id/ll_shopcart_header"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="vertical"        >        <View            android:layout_width="match_parent"            android:layout_height="@dimen/margin_10dp"            android:background="@color/background_color"            android:id="@+id/view"></View>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:gravity="center_vertical"            >            <ImageView                android:id="@+id/iv_item_shopcart_shopselect"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:src="@drawable/shopcart_selected"                android:paddingLeft="@dimen/margin_15dp"                android:paddingRight="@dimen/margin_15dp"                android:paddingTop="@dimen/margin_10dp"                android:paddingBottom="@dimen/margin_10dp"                />            <TextView                android:id="@+id/tv_item_shopcart_shopname"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:drawableLeft="@drawable/shopcart_shop"                android:text="宝儿家服装"                android:padding="@dimen/padding_10dp"                android:drawablePadding="@dimen/padding_5dp"                />        </LinearLayout>    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:gravity="center_vertical"        >        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="vertical"            >            <View                android:layout_width="match_parent"                android:layout_height="@dimen/margin_1dp"                android:background="@color/background_color"                ></View>            <LinearLayout                android:layout_width="match_parent"                android:layout_height="wrap_content">                <ImageView                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:src="@drawable/shopcart_selected"                    android:layout_marginLeft="@dimen/margin_15dp"                    android:layout_marginRight="@dimen/margin_15dp"                    android:visibility="invisible"                    />                <TextView                    android:id="@+id/tv_item_shopcart_clothname"                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:text="穿秋装情侣字母徽章风衣"                    android:paddingLeft="@dimen/padding_10dp"                    android:paddingTop="@dimen/padding_10dp"                    />            </LinearLayout>            <LinearLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:orientation="horizontal"                android:gravity="center_vertical"                >                <ImageView                    android:id="@+id/tv_item_shopcart_clothselect"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:src="@drawable/shopcart_selected"                    android:padding="@dimen/margin_10dp"                    />                <ImageView                    android:id="@+id/iv_item_shopcart_cloth_pic"                    android:layout_width="100dp"                    android:layout_height="120dp"                    android:layout_margin="@dimen/margin_10dp"                    />                <LinearLayout                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:orientation="vertical"                    >                    <TextView                        android:id="@+id/tv_item_shopcart_cloth_price"                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:text="¥185"                        android:textColor="@android:color/holo_red_light"                        android:textSize="14sp"                        />                    <LinearLayout                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:layout_marginTop="@dimen/margin_5dp"                        android:layout_marginBottom="@dimen/margin_5dp"                        >                        <TextView                            android:id="@+id/tv_item_shopcart_cloth_color"                            android:layout_width="wrap_content"                            android:layout_height="wrap_content"                            android:text="颜色:黑色"                            android:textSize="12sp"                            />                        <TextView                            android:id="@+id/tv_item_shopcart_cloth_size"                            android:layout_width="wrap_content"                            android:layout_height="wrap_content"                            android:text="尺寸:XL"                            android:textSize="12sp"                            android:layout_marginLeft="@dimen/margin_10dp"                            />                    </LinearLayout>                    <LinearLayout                        android:layout_width="match_parent"                        android:layout_height="wrap_content"                        android:gravity="center_vertical"                        >                        <ImageView                            android:id="@+id/iv_item_shopcart_cloth_minus"                            android:layout_width="wrap_content"                            android:layout_height="wrap_content"                            android:src="@drawable/shopcart_minus_grey"                            />                        <TextView                            android:id="@+id/et_item_shopcart_cloth_num"                            android:layout_width="wrap_content"                            android:layout_height="wrap_content"                            android:paddingTop="@dimen/padding_2dp"                            android:paddingBottom="@dimen/padding_2dp"                            android:paddingLeft="@dimen/padding_20dp"                            android:paddingRight="@dimen/padding_20dp"                            android:background="@drawable/shopcart_add_btn"                            android:layout_marginLeft="@dimen/margin_5dp"                            android:text="1"                            />                        <ImageView                            android:id="@+id/iv_item_shopcart_cloth_add"                            android:layout_width="wrap_content"                            android:layout_height="wrap_content"                            android:src="@drawable/shopcart_add_red"                            android:layout_marginLeft="@dimen/margin_5dp"                            />                    </LinearLayout>                </LinearLayout>                <View                    android:layout_width="@dimen/margin_1dp"                    android:layout_height="match_parent"                    android:layout_marginTop="@dimen/padding_10dp"                    android:layout_marginBottom="@dimen/padding_10dp"                    android:background="@color/splitline_color"                    ></View>                <ImageView                    android:id="@+id/iv_item_shopcart_cloth_delete"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:padding="@dimen/margin_20dp"                    android:src="@drawable/shopcart_delete"                    />            </LinearLayout>        </LinearLayout>    </LinearLayout>    <View        android:layout_width="match_parent"        android:layout_height="@dimen/margin_1dp"        android:background="@color/background_color"        ></View></LinearLayout>
login_box    login_btn    shopcart_add_btn 3种样式是deawable里的

样式
login_box

 

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">    <corners android:radius="@dimen/height_200dp"></corners>    <stroke android:color="@color/default_icon_color" android:width="1dp"></stroke></shape>
login_btn 样式

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">    <corners android:radius="@dimen/height_200dp"></corners>    <solid android:color="@color/pressed_icon_color"></solid></shape>

shopcart_add_btn.xml  样式

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">    <corners android:radius="@dimen/height_200dp"></corners>    <stroke android:color="@color/background_color" android:width="1dp"></stroke></shape>

Values里的   color颜色     dimens

color颜色

<?xml version="1.0" encoding="utf-8"?><resources>    <color name="colorPrimary">#3F51B5</color>    <color name="colorPrimaryDark">#303F9F</color>    <color name="colorAccent">#e53e42</color>    <!--背景颜色-->    <color name="toolbar_color">#f8f8f8</color>    <color name="background_color">#f6f6f6</color>    <color name="edittext_noenter_color">#f5f5f5</color>    <!--辅助色-->    <color name="support_yellow">#f9a340</color>    <color name="btn_unselect_color">#f4736e</color>    <!--分割线-->    <color name="splitline_color">#dddddd</color>    <!--文字-->    <color name="notice_text_color">#999999</color>    <color name="default_text_color">#666666</color>    <color name="main_black_text">#333333</color>    <color name="main_red_text">#e53e42</color>    <color name="main_white_text">#ffffff</color>    <color name="protocol_text">#3C68FE</color>    <!--图标-->    <color name="abate_icon_color">#bbbbbb</color>    <color name="default_icon_color">#999999</color>    <color name="pressed_icon_color">#e53e42</color>    <!--CycleViewPager-->    <color name="cycle_image_bg">#44222222</color>    <!-- 透明 -->    <color name="transparent">#00000000</color></resources>
dimens

<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>

    <dimen name="common_button_size">15sp</dimen>
    <dimen name="common_title_size">18sp</dimen>
    <dimen name="common_font_size">14sp</dimen>
    <dimen name="common_smail_font_size">12sp</dimen>

    <dimen name="common_font_size_16">16sp</dimen>
    <dimen name="common_font_size_14">14sp</dimen>
    <dimen name="common_font_size_12">12sp</dimen>
    <dimen name="car_radio_margin">10dp</dimen>
    <dimen name="car_style_margin_top">5dp</dimen>
    <dimen name="car_drawable_left_margin">2dp</dimen>
    <dimen name="coupons_margin_left">10dp</dimen>
    <dimen name="coupons_margin_top">2dp</dimen>
    <dimen name="margin_10">10dp</dimen>


    <dimen name="padding_left">14dp</dimen>
    <dimen name="padding_right">14dp</dimen>
    <dimen name="margin_left">14dp</dimen>
    <dimen name="margin_right">14dp</dimen>

    <!--外边距-->
    <dimen name="margin_1dp">1dp</dimen>
    <dimen name="margin_2dp">2dp</dimen>
    <dimen name="margin_3dp">3dp</dimen>
    <dimen name="margin_4dp">4dp</dimen>
    <dimen name="margin_5dp">5dp</dimen>
    <dimen name="margin_6dp">6dp</dimen>
    <dimen name="margin_7dp">7dp</dimen>
    <dimen name="margin_8dp">8dp</dimen>
    <dimen name="margin_10dp">10dp</dimen>
    <dimen name="margin_11dp">10dp</dimen>
    <dimen name="margin_12dp">10dp</dimen>
    <dimen name="margin_15dp">15dp</dimen>
    <dimen name="margin_20dp">20dp</dimen>
    <dimen name="margin_25dp">25dp</dimen>
    <dimen name="margin_30dp">30dp</dimen>
    <dimen name="margin_50dp">50dp</dimen>
    <!--内边距-->
    <dimen name="padding_2dp">2dp</dimen>
    <dimen name="padding_3dp">3dp</dimen>
    <dimen name="padding_4dp">4dp</dimen>
    <dimen name="padding_5dp">5dp</dimen>
    <dimen name="padding_6dp">6dp</dimen>
    <dimen name="padding_7dp">7dp</dimen>
    <dimen name="padding_8dp">8dp</dimen>
    <dimen name="padding_10dp">10dp</dimen>
    <dimen name="padding_12dp">12dp</dimen>
    <dimen name="padding_13dp">13dp</dimen>
    <dimen name="padding_14dp">14dp</dimen>
    <dimen name="padding_15dp">15dp</dimen>
    <dimen name="padding_20dp">20dp</dimen>
    <!--字体大小-->
    <dimen name="textSize_10sp">10sp</dimen>
    <dimen name="textSize_12sp">12sp</dimen>
    <dimen name="textSize_13sp">13sp</dimen>
    <dimen name="textSize_14sp">14sp</dimen>
    <dimen name="textSize_15sp">15sp</dimen>
    <dimen name="textSize_16sp">16sp</dimen>
    <dimen name="textSize_18sp">18sp</dimen>
    <dimen name="textSize_20sp">20sp</dimen>
    <dimen name="textSize_22sp">22sp</dimen>
    <dimen name="textSize_30sp">30sp</dimen>

    <!--城市-->
    <dimen name="side_letter_bar_letter_size">12sp</dimen>
    <dimen name="city_text_size">16sp</dimen>
    <dimen name="side_letter_bar_width">36dp</dimen>
    <dimen name="width_200dp">200dp</dimen>
    <dimen name="height_200dp">200dp</dimen>
    <dimen name="margin_size5dp">5dp</dimen>

</resources>


吐舌头

自己来尝试一下吧

 
原创粉丝点击