一级购物车

《MainModel 》
public interface MainModel {

interface CallBackListener {

    void success(int type, String data);

    void fail(int type, String error);
}

//请求登录
void doLogin(int type, String url, Map<String,String> map,CallBackListener listener);

//获取首页商品
void getShopCar(int type, String url, CallBackListener listener);

//添加购物车
void addShopCar(int type, String url,Map<String,String> headMap, Map<String,String> map,CallBackListener listener);

//获取购物车
void doShopCar(int type,Map<String,String> headMap,String url,CallBackListener listener);

}

《MainModelIml 》
public class MainModelIml implements MainModel {

//登录
@Override
public void doLogin(final int type, String url, Map<String, String> map, final CallBackListener listener) {
    HttpUtils http = new HttpUtils().post(url, map);
    result(type, listener, http);
}

//获取首页商品
@Override
public void getShopCar(int type, String url, CallBackListener listener) {
    result(type, listener, new HttpUtils().get(url));
}

//添加购物车
@Override
public void addShopCar(int type, String url,Map<String,String> headMap, Map<String, String> map, CallBackListener listener) {
    HttpUtils http = new HttpUtils().setHead(headMap).put(url, map);
    result(type, listener, http);
}

//获取购物车
@Override
public void doShopCar(int type,Map<String,String> headMap, String url,CallBackListener listener) {

    HttpUtils httpUtils = new HttpUtils().setHead(headMap).get(url);
    result(type, listener, httpUtils);
}

private void result(final int type, final CallBackListener listener, HttpUtils http) {
    http.result(new HttpListener() {
        @Override
        public void success(String data) {
            listener.success(type, data);
        }

        @Override
        public void fail(String error) {
            listener.fail(type, error);
        }
    });
}

}

《MainPresenter 》
public interface MainPresenter {

//请求登录
void doLogin(int type, String url, Map<String,String> map);

//获取首页商品
void getShopCar(int type, String url);

//添加购物车
void addShopCar(int type, String url,Map<String,String> headMap, Map<String,String> map);


//获取购物车
void doShopCar(int type,Map<String,String> headMap,String url);

}
《MainPresenterIml 》
public class MainPresenterIml implements MainPresenter, MainModel.CallBackListener {
private MainModel mainModel;
private MainView mainView;

public MainPresenterIml(MainModel mainModel, MainView mainView) {
    this.mainModel = mainModel;
    this.mainView = mainView;
}

//登录
@Override
public void doLogin(int type, String url, Map<String, String> map) {
    mainModel.doLogin(type, url, map, this);
}

//获取首页商品
@Override
public void getShopCar(int type, String url) {
    mainModel.getShopCar(type,url,this);
}


//添加购物车
@Override
public void addShopCar(int type, String url,Map<String,String> headMap, Map<String, String> map) {
    mainModel.addShopCar(type,url,headMap,map,this);
}

//查询购物车
@Override
public void doShopCar(int type, Map<String, String> headMap, String url) {
    mainModel.doShopCar(type,headMap,url,this);
}

@Override
public void success(int type, String data) {
    mainView.success(type, data);
}

@Override
public void fail(int type, String error) {
    mainView.fail(type, error);
}


public void destory() {
    if (mainView != null) {
        mainView = null;
    }
    if (mainModel != null) {
        mainModel = null;
    }
    System.gc();
}

}

《MainView 》
public interface MainView {

void success(int type, String data);

void fail(int type, String error);

}
《HttpService 》
public interface HttpService {

@GET
Observable<ResponseBody> get(@Url String url,@HeaderMap Map<String,String> headMap);

@POST
Observable<ResponseBody> post(@Url String url,
                              @HeaderMap Map<String,String> headMap,
                              @QueryMap Map<String,String> map);

@PUT
Observable<ResponseBody> put(@Url String url,
                              @HeaderMap Map<String,String> headMap,
                              @QueryMap Map<String,String> map);

}

《HttpUtils 》
public class HttpUtils {

private String baseUrl = "http://172.17.8.100";

//用来添加头参
private Map<String, String> headMap = new HashMap<>();

public HttpUtils setHead(Map<String, String> headMap) {
    this.headMap = headMap;
    return this;
}

public HttpUtils put(String url, Map<String, String> map) {
    HttpService service = null;
    try {
        service = getHttpService();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Observable<ResponseBody> ob = service.put(url, headMap, map);
    send(ob);

    return this;
}

//post请求
public HttpUtils post(String url, Map<String, String> map) {
    HttpService service = null;
    try {
        service = getHttpService();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Observable<ResponseBody> ob = service.post(url, headMap, map);
    send(ob);

    return this;
}

//get请求
public HttpUtils get(String url) {
    HttpService service = null;
    try {
        service = getHttpService();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Observable<ResponseBody> ob = service.get(url,headMap);
    send(ob);
    return this;
}

//订阅
private void send(Observable<ResponseBody> ob) {
    ob.subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Observer<ResponseBody>() {
                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onNext(ResponseBody responseBody) {
                    try {
                        mHttpListener.success(responseBody.string());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onError(Throwable e) {
                    mHttpListener.fail(e.getMessage());
                }

                @Override
                public void onComplete() {

                }
            });
}

private HttpService getHttpService() throws IOException {
    File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
    Cache cache = new Cache(file, 10 * 1024);
    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .addInterceptor(new Interceptor() {
                @Override
                public Response intercept(Chain chain) throws IOException {
                    Request request = chain.request();

// request.newBuilder().addHeader()
return chain.proceed(request);
}
})
.cache(cache)
.build();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(okHttpClient)
            .build();

    return retrofit.create(HttpService.class);
}

private HttpListener mHttpListener;

public void result(HttpListener mHttpListener) {
    this.mHttpListener = mHttpListener;
}

}

《HttpListener 》
public interface HttpListener {

void success(String data);

void fail(String error);

}

《ShopCarAddView 自定义加减器》
public class ShopCarAddView extends RelativeLayout implements View.OnClickListener {
private EditText mEdText;

public ShopCarAddView(Context context) {
    super(context);
    init(context);
}

public ShopCarAddView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context);
}
private Context mContext;
private void init(Context context) {
    this.mContext = context;
    View view = View.inflate(context, R.layout.shop_car_add, null);
    mEdText = (EditText) view.findViewById(R.id.ed_text);
    view.findViewById(R.id.tv_jian).setOnClickListener(this);
    view.findViewById(R.id.tv_jia).setOnClickListener(this);

    addView(view);
}

public void setNum(int num) {
    mEdText.setText(num + "");
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.tv_jia://加
            String num = mEdText.getText().toString().trim();
            int n = Integer.parseInt(num);
            n++;
            mChangeNumListener.num(n);
            mEdText.setText(n + "");
            break;
        case R.id.tv_jian://减
            String numJian = mEdText.getText().toString().trim();
            int nJian = Integer.parseInt(numJian);
            if (nJian == 1) {
                Toast.makeText(mContext, "至少得有一个商品哦~", Toast.LENGTH_LONG).show();
                return;
            }
            nJian--;
            mChangeNumListener.num(nJian);
            mEdText.setText(nJian + "");
            break;
    }
}

private ChangeNumListener mChangeNumListener;

public void setChangeNumListener(ChangeNumListener mChangeNumListener) {
    this.mChangeNumListener = mChangeNumListener;
}

public interface ChangeNumListener {
    void num(int num);
}

}

《App Fresco缓存路径 》
public class App extends Application{
@Override
public void onCreate() {
super.onCreate();
Fresco.initialize(this, ImagePipelineConfig.newBuilder(App.this)
.setMainDiskCacheConfig(
DiskCacheConfig.newBuilder(this)
//磁盘缓存路径
.setBaseDirectoryPath(new File(Environment.getExternalStorageDirectory().getAbsolutePath())) // 注意Android运行时权限。
.setMaxCacheSize(10 * 1024 * 1024)
.build()
)
.build()
);
}
}

《HomeFragment 首页》
public class HomeFragment extends Fragment implements MainView {
private RecyclerView mRecyler;
private ShopCarAdapter shopCarAdapter;
private HashMap<String, String> headMap = new HashMap<>();
private MainPresenterIml mainPresenterIml;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = View.inflate(getActivity(), R.layout.fragment_home, null);
    return view;

}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mRecyler = (RecyclerView) getActivity().findViewById(R.id.recycler);

    shopCarAdapter = new ShopCarAdapter(getActivity());
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2);
    mRecyler.setLayoutManager(gridLayoutManager);
    mRecyler.setAdapter(shopCarAdapter);

    headMap = new HashMap<>();
    SharedPreferences sp = getActivity().getSharedPreferences("shop", 0);
    int userId = sp.getInt("userId", 0);
    String sessionId = sp.getString("sessionId", "");
    headMap.put("userId", userId + "");
    headMap.put("sessionId", sessionId);

    mainPresenterIml = new MainPresenterIml(new MainModelIml(), this);
    mainPresenterIml.getShopCar(0, "/small/commodity/v1/findCommodityByKeyword?page=1&count=10&keyword=手机");

    shopCarAdapter.setOnItemClickListenrer(new ShopCarAdapter.OnItemClickListenrer() {
        @Override
        public void onItemClick(int id) {
            try {
                boolean isHave = true;
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject json = jsonArray.getJSONObject(i);
                    int commodityId = json.getInt("commodityId");
                    int count = json.getInt("count");
                    if (id == commodityId) {
                        isHave = false;
                        count++;
                        json.put("count", count);
                    }
                }

                if (isHave) {//之前购物车里没有
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("commodityId", id);
                    jsonObject.put("count", "1");
                    jsonArray.put(jsonObject);
                }


                Map<String, String> map = new HashMap<>();
                map.put("data", jsonArray.toString());
                mainPresenterIml.addShopCar(2, "/small/order/verify/v1/syncShoppingCart", headMap, map);

            } catch (Exception e) {

            }


        }
    });

}

private JSONArray jsonArray = new JSONArray();

@Override
public void success(int type, String data) {
    //Toast.makeText(getActivity(), data, Toast.LENGTH_LONG).show();
    if (type == 0) {
        ShopCarBean bean = new Gson().fromJson(data, ShopCarBean.class);
        shopCarAdapter.setList(bean.getResult());
        //去执行添加购物车
        mainPresenterIml.doShopCar(1, headMap, "/small/order/verify/v1/findShoppingCart");
    } else if (type == 1) {//查询购物车
        Log.i("success", data);
        CarBean bean = new Gson().fromJson(data, CarBean.class);
        try {
            for (int i = 0; i < bean.getResult().size(); i++) {
                CarBean.ResultBean b = bean.getResult().get(i);
                int id = b.getCommodityId();
                int count = b.getCount();
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("commodityId", id);
                jsonObject.put("count", count);
                jsonArray.put(jsonObject);
            }
        } catch (Exception e) {

        }

    } else if (type == 2) {//添加购物车
        try {
            JSONObject jsonObject=new JSONObject(data);
            String status=jsonObject.getString("status");
            if(status.equals("0000")){
                Toast.makeText(getActivity(),"添加成功",Toast.LENGTH_LONG).show();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        Log.i("success", data);
    }

}

@Override
public void fail(int type, String error) {
    Log.i("fail", error);
}

}

《购物车》
public class ShopCarFragment extends Fragment implements MainView {
private MainPresenterIml mainPresenterIml;
private HashMap<String, String> headMap = new HashMap<>();
private RecyclerView mRecyclerView;
private CarAdapter carAdapter;
private List<CarBean.ResultBean> listBean = new ArrayList<>();
private CheckBox allCheck;
private TextView mAllPrice, mAllNum;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = View.inflate(getActivity(), R.layout.fragment_shop_car, null);
    return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.shop_recycler);
    mAllPrice = (TextView) getActivity().findViewById(R.id.tv_price);
    mAllNum = (TextView) getActivity().findViewById(R.id.tv_num);
    //全选
    allCheck = (CheckBox) getActivity().findViewById(R.id.checkbox);
    carAdapter = new CarAdapter(getActivity());
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(linearLayoutManager);
    mRecyclerView.setAdapter(carAdapter);


    mainPresenterIml = new MainPresenterIml(new MainModelIml(), this);

    carAdapter.setOnChangeDataListener(new CarAdapter.OnChangeDataListener() {
        @Override
        public void changeList(List<CarBean.ResultBean> list) {
            Log.i("changeList",list.size()+"");
            float priceAll = 0;
            int countAll = 0;
            int num = 0;
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).isCheck()) {//选中
                    num++;
                    int price = list.get(i).getPrice();
                    int count = list.get(i).getCount();
                    priceAll = priceAll + price * count;//获取总价
                    countAll = countAll + count;//获取数量
                }
            }

            if (num == list.size()) {//所有的商品都选中
                allCheck.setChecked(true);
            } else {
                allCheck.setChecked(false);
            }

            mAllPrice.setText(priceAll + "");
            mAllNum.setText("去结算(" + countAll + ")");

        }
    });


    getActivity().findViewById(R.id.checkbox).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean isCheck = allCheck.isChecked();
            float priceAll = 0;
            int countAll = 0;
            for (int i = 0; i < listBean.size(); i++) {
                listBean.get(i).setCheck(isCheck);
                int price = listBean.get(i).getPrice();
                int count = listBean.get(i).getCount();
                priceAll = priceAll + price * count;//获取总价
                countAll = countAll + count;//获取数量
            }

            if (!isCheck) {
                priceAll = 0;
                countAll = 0;
            }
            mAllPrice.setText(priceAll + "");
            mAllNum.setText("去结算(" + countAll + ")");
            carAdapter.setList(listBean);
        }
    });

}

@Override
public void success(int type, String data) {
    Log.i("success", data);

    CarBean bean = new Gson().fromJson(data, CarBean.class);
    if (bean.getStatus().equals("0000")) {//登录成功
        listBean = bean.getResult();
        carAdapter.setList(listBean);
    } else {
        Toast.makeText(getActivity(), "请先登录", Toast.LENGTH_LONG).show();
    }


}

@Override
public void fail(int type, String error) {

}

//刷新购物车数据
public void notifyData() {
    headMap = new HashMap<>();
    SharedPreferences sp = getActivity().getSharedPreferences("shop", 0);
    int userId = sp.getInt("userId", 0);
    String sessionId = sp.getString("sessionId", "");
    headMap.put("userId", userId + "");
    headMap.put("sessionId", sessionId);
    mainPresenterIml.doShopCar(0, headMap, "/small/order/verify/v1/findShoppingCart");
}

}

《我的》
public class AccountFragment extends Fragment implements MainView {
private EditText edPhone, edPass;
private MainPresenterIml mainPresenterIml;
private RelativeLayout loginSuccess;
private SimpleDraweeView mSimpleDraweeView;
private TextView mTvNickName;
private RelativeLayout loginLayout;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = View.inflate(getActivity(), R.layout.fragment_account, null);
    return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    edPhone = (EditText) getActivity().findViewById(R.id.ed_phone);
    edPass = (EditText) getActivity().findViewById(R.id.ed_password);
    loginSuccess=(RelativeLayout)getActivity().findViewById(R.id.login_success);
    mSimpleDraweeView=(SimpleDraweeView)getActivity().findViewById(R.id.simple);
    mTvNickName=(TextView)getActivity().findViewById(R.id.tv_nick_name);
    loginLayout=(RelativeLayout)getActivity().findViewById(R.id.login_layout);
    getActivity().findViewById(R.id.login).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            doLogin();
        }
    });

    mainPresenterIml = new MainPresenterIml(new MainModelIml(), this);
}

//去请求登录
private void doLogin() {
    String phone = edPhone.getText().toString().trim();
    String pass = edPass.getText().toString().trim();
    if (TextUtils.isEmpty(phone)) {
        Toast.makeText(getActivity(), "请输入手机号", Toast.LENGTH_LONG).show();
        return;
    }
    if (TextUtils.isEmpty(pass)) {
        Toast.makeText(getActivity(), "请输入密码", Toast.LENGTH_LONG).show();
        return;
    }

    Map<String, String> map = new HashMap<>();
    map.put("phone", phone);
    map.put("pwd", pass);
    mainPresenterIml.doLogin(0, "/small/user/v1/login", map);
}

@Override
public void success(int type, String data) {
    //Toast.makeText(getActivity(), data, Toast.LENGTH_LONG).show();

    loginSuccess.setVisibility(View.VISIBLE);//登录成功之后显示
    loginLayout.setVisibility(View.GONE);
    UserBean bean = new Gson().fromJson(data, UserBean.class);

    String headPic = bean.getResult().getHeadPic();
    String nickName = bean.getResult().getNickName();
    int userId = bean.getResult().getUserId();
    String sessionId = bean.getResult().getSessionId();

    mTvNickName.setText(nickName);
    mSimpleDraweeView.setImageURI(headPic);//设置用户头像

    SharedPreferences sp = getActivity().getSharedPreferences("shop", 0);
    sp.edit().putString("headPic", headPic)
            .putString("nickName", nickName)
            .putInt("userId", userId)
            .putString("sessionId", sessionId).commit();

}

@Override
public void fail(int type, String error) {

}

}

《首页适配器 ShopCarAdapter 》
public class ShopCarAdapter extends RecyclerView.Adapter<ShopCarAdapter.ShopCarViewHolder> {
private List<ShopCarBean.ResultBean> list = new ArrayList<>();

private Context context;

public ShopCarAdapter(Context context) {
    this.context = context;
}

@NonNull
@Override
public ShopCarAdapter.ShopCarViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = View.inflate(context, R.layout.shop_car_adapter, null);
    ShopCarViewHolder shopCarViewHolder = new ShopCarViewHolder(view);
    return shopCarViewHolder;
}

@Override
public void onBindViewHolder(@NonNull ShopCarAdapter.ShopCarViewHolder shopCarViewHolder, final int i) {
    shopCarViewHolder.mSimple.setImageURI(list.get(i).getMasterPic());
    shopCarViewHolder.mTitle.setText(list.get(i).getCommodityName());
    shopCarViewHolder.mPrice.setText(list.get(i).getPrice() + "");
    shopCarViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mOnItemClickListenrer.onItemClick(list.get(i).getCommodityId());
        }
    });
}

@Override
public int getItemCount() {
    return list.size();
}

public void setList(List<ShopCarBean.ResultBean> list) {
    this.list = list;
    notifyDataSetChanged();
}

public class ShopCarViewHolder extends RecyclerView.ViewHolder {
    TextView mTitle, mPrice;
    SimpleDraweeView mSimple;

    public ShopCarViewHolder(@NonNull View itemView) {
        super(itemView);
        mSimple = (SimpleDraweeView) itemView.findViewById(R.id.simple);
        mTitle = (TextView) itemView.findViewById(R.id.tv_title);
        mPrice = (TextView) itemView.findViewById(R.id.tv_price);
    }
}

private OnItemClickListenrer mOnItemClickListenrer;
public void setOnItemClickListenrer(OnItemClickListenrer mOnItemClickListenrer){
    this.mOnItemClickListenrer=mOnItemClickListenrer;
}

public interface OnItemClickListenrer{
    void onItemClick( int i);
}

}

《购物车适配器 CarAdapter 》
public class CarAdapter extends RecyclerView.Adapter<CarAdapter.CarViewHolder> {
private List<CarBean.ResultBean> list = new ArrayList<>();
private Context context;

public CarAdapter(Context context) {
    this.context = context;
}

@NonNull
@Override
public CarAdapter.CarViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = View.inflate(context, R.layout.car_item, null);
    CarViewHolder carViewHolder = new CarViewHolder(view);
    return carViewHolder;
}

@Override
public void onBindViewHolder(@NonNull final CarAdapter.CarViewHolder carViewHolder, final int i) {
    carViewHolder.mTextView.setText(list.get(i).getCommodityName());
    carViewHolder.mSimple.setImageURI(list.get(i).getPic());
    carViewHolder.mPrice.setText(list.get(i).getPrice() + "");
    carViewHolder.mShopCarView.setNum(list.get(i).getCount());

    carViewHolder.mCheck.setChecked(list.get(i).isCheck());

    carViewHolder.mCheck.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean ischeck=carViewHolder.mCheck.isChecked();
            list.get(i).setCheck(ischeck);
            mOnChangeDataListener.changeList(list);
        }
    });

    carViewHolder.mShopCarView.setChangeNumListener(new ShopCarAddView.ChangeNumListener() {
        @Override
        public void num(int num) {
            list.get(i).setCount(num);
            mOnChangeDataListener.changeList(list);
        }
    });
}

@Override
public int getItemCount() {
    if (list == null) {
        return 0;
    }
    return list.size();
}

public void setList(List<CarBean.ResultBean> list) {
    this.list = list;
    notifyDataSetChanged();
}

public class CarViewHolder extends RecyclerView.ViewHolder {
    ShopCarAddView mShopCarView;
    TextView mTextView, mPrice;
    SimpleDraweeView mSimple;
    CheckBox mCheck;

    public CarViewHolder(@NonNull View itemView) {
        super(itemView);
        mCheck = (CheckBox) itemView.findViewById(R.id.checkbox);
        mSimple = (SimpleDraweeView) itemView.findViewById(R.id.simple);
        mTextView = (TextView) itemView.findViewById(R.id.tv_title);
        mPrice = (TextView) itemView.findViewById(R.id.tv_price);
        mShopCarView = (ShopCarAddView) itemView.findViewById(R.id.carview);
    }
}


private OnChangeDataListener mOnChangeDataListener;

public void setOnChangeDataListener(OnChangeDataListener mOnChangeDataListener) {
    this.mOnChangeDataListener = mOnChangeDataListener;
}

public interface OnChangeDataListener {

    void changeList(List<CarBean.ResultBean> list);
}

}

《购物车布局》

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_marginTop="10dp">

    <CheckBox
        android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true" />

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/simple"
        android:layout_width="100dp"
        android:layout_height="80dp"
        android:layout_toRightOf="@+id/checkbox" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/simple">

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">

            <TextView
                android:id="@+id/tv_price"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#d43c3c" />

            <!--自定义的加减器-->

            <com.shopcar426.view.ShopCarAddView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/carview"
                android:layout_alignParentRight="true"
                />
        </RelativeLayout>

    </RelativeLayout>


</RelativeLayout>
==《登录布局》==
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:id="@+id/login_layout"
    >

    <EditText
        android:id="@+id/ed_phone"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@drawable/ed_bg"
        android:hint="请输入手机号"
        android:inputType="phone"
        android:paddingLeft="5dp" />

    <EditText
        android:id="@+id/ed_password"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/ed_phone"
        android:layout_marginTop="10dp"
        android:background="@drawable/ed_bg"
        android:hint="请输入密码"
        android:paddingLeft="5dp" />

    <Button
        android:id="@+id/login"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/ed_password"
        android:layout_marginTop="10dp"
        android:background="@drawable/btn_bg"
        android:text="登录"
        android:textColor="#ffffff" />
</RelativeLayout>

<!--登录过后展示的UI-->

<RelativeLayout
    android:id="@+id/login_success"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:visibility="gone">

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/simple"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp" />

    <TextView
        android:id="@+id/tv_nick_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/simple"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp" />

</RelativeLayout>
==《购物车外框布局》==
<android.support.v7.widget.RecyclerView
    android:id="@+id/shop_recycler"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/layout" />

<RelativeLayout
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true">

    <CheckBox
        android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="全选" />

    <TextView
        android:id="@+id/tv_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/checkbox"
        android:text="0.0"
        android:textColor="#d43c3c" />

    <RelativeLayout
        android:layout_width="100dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:background="#d43c3c">

        <TextView
            android:id="@+id/tv_num"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="去结算(0)"
            android:textColor="#ffffff" />
    </RelativeLayout>


</RelativeLayout>
==《 依赖 implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' implementation 'com.squareup.retrofit2:converter-gson:2.4.0' implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' implementation 'com.facebook.fresco:fresco:1.13.0' implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:design:28.0.0' 》==
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值