导入依赖包:
adapter——Rlv_Adaptercompile 'com.facebook.fresco:fresco:0.11.0' compile 'com.squareup.okhttp3:logging-interceptor:3.4.1' compile 'com.android.support:recyclerview-v7:26.1.0' compile 'com.squareup.okhttp3:okhttp:3.9.0' compile 'com.squareup.okio:okio:1.13.0' compile 'com.google.code.gson:gson:2.8.2' compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.squareup.picasso:picasso:2.5.2' compile 'org.greenrobot:eventbus:3.0.0' compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4' compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4' compile 'io.reactivex:rxjava:1.1.0' compile 'io.reactivex:rxandroid:1.1.0' compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
package com.example.xiehaojia_20171219.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.CheckBox; import android.widget.ImageView; import android.widget.TextView; import com.example.xiehaojia_20171219.R; import com.example.xiehaojia_20171219.bean.CartBean; import com.example.xiehaojia_20171219.eventbusevent.MessageEvent; import com.example.xiehaojia_20171219.eventbusevent.PriceAndCountEvent; import com.facebook.drawee.view.SimpleDraweeView; import org.greenrobot.eventbus.EventBus; import java.util.List; public class Rlv_Adapter extends RecyclerView.Adapter<Rlv_Adapter.MyViewHodler> { private Context context; private List<CartBean.DataBean.ListBean> list; public Rlv_Adapter(Context context, List<CartBean.DataBean.ListBean> list) { this.context = context; this.list = list; } @Override public MyViewHodler onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(context).inflate(R.layout.rlv, null); return new MyViewHodler(view); } @Override public void onBindViewHolder(final MyViewHodler holder, final int position) { final CartBean.DataBean.ListBean listBean = list.get(position); holder.mBoxCart.setChecked(listBean.isCheck()); holder.mGoodnameCart.setText(listBean.getTitle()); holder.mGoodpriceCart.setText(listBean.getPrice() + ""); holder.mNumCart.setText(listBean.getNum() + ""); String[] split = listBean.getImages().split("\\|"); holder.mShopIvCart.setImageURI(split[0]); holder.mBoxCart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean checked = holder.mBoxCart.isChecked(); listBean.setCheck(checked); boolean checkBox = selsectAllCheckBox(); changeAllCbState(checkBox); PriceAndCountEvent priceAndCountEvent = compute(); EventBus.getDefault().post(priceAndCountEvent); notifyDataSetChanged(); } }); //加号的点击监听 holder.mJiaCart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //现获取当前的数量 int num = listBean.getNum(); //数量加1后显示在界面 holder.mNumCart.setText(++num + ""); //把数量存进对象 listBean.setNum(num); //获取当前子条目的复选框的选中状态 if (holder.mBoxCart.isChecked()) { 当前的复选框为选中状态使 改变总数和总价 PriceAndCountEvent priceAndCountEvent = compute(); EventBus.getDefault().post(priceAndCountEvent); } } }); //减号的点击监听 holder.mJianCart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //获取当前的数量 int num = listBean.getNum(); //当前的数量为1时 直接返回 if (num == 1) { return; } //改变当前的数量显示 holder.mNumCart.setText(--num + ""); //把当前的数量存进对象 listBean.setNum(num); //获取当前子条目的复选框的选中状态 if (holder.mBoxCart.isChecked()) { 当前的复选框为选中状态使 改变总数和总价 PriceAndCountEvent priceAndCountEvent = compute(); EventBus.getDefault().post(priceAndCountEvent); } } }); //子条目删除的点击监听 holder.mDelectCart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //删除子条目对用的数据 list.remove(position); //修改总数和总价 EventBus.getDefault().post(compute()); //刷新适配器 notifyDataSetChanged(); } }); } /** * 改变全选Box的状态 */ private void changeAllCbState(boolean flag) { MessageEvent messageEvent = new MessageEvent(); messageEvent.setChecked(flag); EventBus.getDefault().post(messageEvent); } /** * 计算列表中,选中的钱和数量 */ private PriceAndCountEvent compute() { int count = 0; int price = 0; //遍历子条目集合 for (int i = 0; i < list.size(); i++) { CartBean.DataBean.ListBean listBean = list.get(i); //判断当前子条目是否被选中 if (listBean.isCheck()) { //选中则增加价钱和数量 price += listBean.getNum() * listBean.getPrice(); count += listBean.getNum(); } } //实例化一个对象 返回 return new PriceAndCountEvent(price, count); } /** * 遍历集合,查询是否全选 */ private boolean selsectAllCheckBox() { for (int i = 0; i < list.size(); i++) { if (!list.get(i).isCheck()) { return false; } } return true; } /** * 设置全选、反选 */ public void changeAllListCbState(boolean flag) { //遍历组的集合 for (int i = 0; i < list.size(); i++) { list.get(i).setCheck(flag); } //返回总数量,总价钱 EventBus.getDefault().post(compute()); //刷新 notifyDataSetChanged(); } @Override public int getItemCount() { return list.size(); } class MyViewHodler extends RecyclerView.ViewHolder { private CheckBox mBoxCart; private SimpleDraweeView mShopIvCart; private TextView mDelectCart; private TextView mGoodnameCart; private TextView mGoodpriceCart; private ImageView mJianCart; private TextView mNumCart; private ImageView mJiaCart; public MyViewHodler(View itemView) { super(itemView); mBoxCart = itemView.findViewById(R.id.cart_box); mShopIvCart = itemView.findViewById(R.id.cart_shopIv); mDelectCart = itemView.findViewById(R.id.cart_delect); mGoodnameCart = itemView.findViewById(R.id.cart_goodname); mGoodpriceCart = itemView.findViewById(R.id.cart_goodprice); mJianCart = itemView.findViewById(R.id.cart_jian); mNumCart = itemView.findViewById(R.id.cart_num); mJiaCart = itemView.findViewById(R.id.cart_jia); } } }
bean——CartBean
http://120.27.23.105/product/getCarts?uid=71&source=android
eventbusevent——MessageEvent
package com.example.xiehaojia_20171219.eventbusevent; /** * Created by on 2017/12/19. */ public class MessageEvent { private boolean checked; public boolean isChecked() { return checked; } public void setChecked(boolean checked) { this.checked = checked; } }
eventbusevent——PriceAndCountEventpackage com.example.xiehaojia_20171219.eventbusevent; /** * Created by on 2017/12/19. */ public class PriceAndCountEvent { private int price; private int count; public PriceAndCountEvent(int price, int count) { this.price = price; this.count = count; } public PriceAndCountEvent() { } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } }
model——IShopCart_Mpackage com.example.xiehaojia_20171219.model; import com.example.xiehaojia_20171219.bean.CartBean; import com.example.xiehaojia_20171219.net.OnNetListenner; import java.util.Map; /** * Created by on 2017/12/19. */ public interface IShopCart_M { void doGetCartBean(OnNetListenner<CartBean> onNetListenner); }
model——ShopCart_Mpackage com.example.xiehaojia_20171219.model; /** * Created by on 2017/12/19. */ import android.util.Log; import android.widget.Toast; import com.example.xiehaojia_20171219.bean.CartBean; import com.example.xiehaojia_20171219.net.API; import com.example.xiehaojia_20171219.net.MyOkHttpUtil; import com.example.xiehaojia_20171219.net.OnNetListenner; import com.google.gson.Gson; import java.io.IOException; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; public class ShopCart_M implements IShopCart_M { @Override public void doGetCartBean(final OnNetListenner<CartBean> onNetListenner) { MyOkHttpUtil.getOkHttpUtil().doPost(API.CARTS,new Callback() { @Override public void onFailure(Call call, IOException e) { onNetListenner.doShiBai(e); } @Override public void onResponse(Call call, Response response) throws IOException { String json = response.body().string(); Gson gson=new Gson(); CartBean cartBean = gson.fromJson(json, CartBean.class); onNetListenner.doChengGong(cartBean); } }); } }
net——APIpackage com.example.xiehaojia_20171219.net; /** * Created by lenovo on 2017/12/19. */ public interface API { /** * "uid", "71" */ String CARTS="http://120.27.23.105/product/getCarts?uid=71&source=android"; //http://120.27.23.105/product/getCarts?uid=71&source=android }
net——MyOkHttpUtilpackage com.example.xiehaojia_20171219.net; /** * Created by lenovo on 2017/12/19. */ import java.io.File; import java.util.Map; import okhttp3.Callback; import okhttp3.FormBody; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; public class MyOkHttpUtil { private static MyOkHttpUtil okHttpUtil; private final OkHttpClient client; private MyOkHttpUtil() { client = new OkHttpClient.Builder() .build(); } public static MyOkHttpUtil getOkHttpUtil() { if (okHttpUtil == null) { synchronized (MyOkHttpUtil.class) { if (okHttpUtil == null) { okHttpUtil = new MyOkHttpUtil(); } } } return okHttpUtil; } public void doGet(String url, Callback callback) { Request request = new Request.Builder().url(url).build(); client.newCall(request).enqueue(callback); } public void doPost(String url, Callback callback) { FormBody.Builder builder = new FormBody.Builder(); RequestBody body = builder.build(); Request request = new Request.Builder().url(url).post(body).build(); client.newCall(request).enqueue(callback); } public void loadFile(String url, File file, String fileName, Callback callback) { //设置文件类型 RequestBody requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), file); //设置请求体 RequestBody body = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart("image", fileName, requestBody) .build(); //请求方式 Request request = new Request.Builder().url(url).post(body).build(); client.newCall(request).enqueue(callback); } public void doDown(String url,Callback callback){ Request build = new Request.Builder().url(url).build(); client.newCall(build).enqueue(callback); } }
net——MyOkHttpUtilpackage com.example.xiehaojia_20171219.net; /** * Created by lenovo on 2017/12/19. */ public interface OnNetListenner<T> { void doChengGong(T t); void doShiBai(Exception e); }
presenter——IDataPresenterpackage com.example.xiehaojia_20171219.presenter; import com.example.xiehaojia_20171219.view.IShopCart_V; /** * P层和V层绑定 */ public interface IDataPresenter<T extends IShopCart_V> { //绑定方法 public void attach(T view); //解绑方法 public void detach(); }
presenter——ShopCart_Ppackage com.example.xiehaojia_20171219.presenter; import com.example.xiehaojia_20171219.bean.CartBean; import com.example.xiehaojia_20171219.model.ShopCart_M; import com.example.xiehaojia_20171219.net.OnNetListenner; import com.example.xiehaojia_20171219.view.IShopCart_V; import java.lang.ref.SoftReference; import java.util.HashMap; import java.util.Map; public class ShopCart_P implements IDataPresenter<IShopCart_V>{ private IShopCart_V shopCartV; private final ShopCart_M shopCartM; SoftReference<IShopCart_V> shopCart_vSoftReference; public ShopCart_P(IShopCart_V shopCartV) { shopCartM = new ShopCart_M(); attach(shopCartV); } public void doGetCartBean() { Map<String, String> map = new HashMap<>(); map.put("uid", "71"); shopCartM.doGetCartBean(new OnNetListenner<CartBean>() { @Override public void doChengGong(CartBean cartBean) { shopCart_vSoftReference.get().setCartBean(cartBean ); } @Override public void doShiBai(Exception e) { e.printStackTrace(); } }); } //绑定 @Override public void attach(IShopCart_V view) { shopCart_vSoftReference=new SoftReference<IShopCart_V>(view); } //解绑 @Override public void detach() { shopCart_vSoftReference.clear(); } }
view——IShopCart_Vpackage com.example.xiehaojia_20171219.view; import com.example.xiehaojia_20171219.bean.CartBean; /** * Created by lenovo on 2017/12/19. */ public interface IShopCart_V { void setCartBean(CartBean carBean); }
CustomViewpackage com.example.xiehaojia_20171219; /** * Created by lenovo on 2017/12/19. */ import android.content.Context; import android.support.annotation.Nullable; import android.text.Editable; import android.text.TextWatcher; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Toast; public class CustomView extends LinearLayout{ public CustomView(Context context) { super(context); } public CustomView(final Context context, @Nullable AttributeSet attrs) { super(context, attrs); View view = LayoutInflater.from(context).inflate(R.layout.custom_layout,null); addView(view); Button jian = (Button) view.findViewById(R.id.jian); Button jia = (Button) view.findViewById(R.id.jia); final EditText num = (EditText) view.findViewById(R.id.num); //减号 jian.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String result = num.getText().toString().trim(); int integerResult = Integer.valueOf(result); //给做个限制 if(integerResult > 1){ integerResult = integerResult - 1; num.setText(integerResult + ""); }else{ Toast.makeText(context, "最小数量为1", Toast.LENGTH_SHORT).show(); } if(listener != null){ listener.onChange(integerResult); } } }); //加号 jia.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String result = num.getText().toString().trim(); int integerResult = Integer.valueOf(result); if(integerResult < 10000){ integerResult = integerResult + 1; num.setText(integerResult +""); }else{ Toast.makeText(context, "已经超出最大值", Toast.LENGTH_SHORT).show(); } if(listener != null ){ listener.onChange(integerResult); } } }); num.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { Log.i("beforeTextChanged",s+"-----"+start+"-------"+count+"-----"+after); } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { Log.i("onTextChanged",s+"-----"+start+"-------"+before+"-----"+count); } @Override public void afterTextChanged(Editable s) { if(listener != null ){ listener.onChange(Long.valueOf(s.toString())); } } }); } public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public ChangeListener listener; public void setListener(ChangeListener listener){ this.listener = listener; } public interface ChangeListener{ public void onChange(long count); } }
MainActivitypackage com.example.xiehaojia_20171219; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.CheckBox; import android.widget.TextView; import com.example.xiehaojia_20171219.adapter.Rlv_Adapter; import com.example.xiehaojia_20171219.bean.CartBean; import com.example.xiehaojia_20171219.eventbusevent.MessageEvent; import com.example.xiehaojia_20171219.eventbusevent.PriceAndCountEvent; import com.example.xiehaojia_20171219.presenter.ShopCart_P; import com.example.xiehaojia_20171219.view.IShopCart_V; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity implements View.OnClickListener, IShopCart_V { private CheckBox mFootBoxCart; private TextView mFootTotalPriceCart; private TextView mFootTotalCountCart; private List<CartBean.DataBean.ListBean> list; private RecyclerView mRlvMain; private Rlv_Adapter adapter; ShopCart_P shopCartP; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); EventBus.getDefault().register(this); initView(); mFootBoxCart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { adapter.changeAllListCbState(mFootBoxCart.isChecked()); } }); } private void initView() { list = new ArrayList<>(); mFootBoxCart = (CheckBox) findViewById(R.id.cart_foot_box); mFootBoxCart.setOnClickListener(this); mFootTotalPriceCart = (TextView) findViewById(R.id.cart_foot_totalPrice); mFootTotalCountCart = (TextView) findViewById(R.id.cart_foot_totalCount); mRlvMain = (RecyclerView) findViewById(R.id.main_rlv); mRlvMain.setLayoutManager(new LinearLayoutManager(MainActivity.this)); shopCartP= new ShopCart_P(this); shopCartP.doGetCartBean(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.cart_foot_box: // TODO 17/11/20 break; default: break; } } @Override public void setCartBean(final CartBean cartBean) { runOnUiThread(new Runnable() { @Override public void run() { //获取数据 List<CartBean.DataBean> data = cartBean.getData(); for (int i = 0; i < data.size(); i++) { List<CartBean.DataBean.ListBean> listBeen = data.get(i).getList(); for (int j = 0; j < listBeen.size(); j++) { list.add(listBeen.get(j)); } } adapter = new Rlv_Adapter(MainActivity.this, list); mRlvMain.setAdapter(adapter); } }); } @Subscribe public void onMessageEvent(MessageEvent event) { mFootBoxCart.setChecked(event.isChecked()); } @Subscribe public void onMessageEvent(PriceAndCountEvent event) { mFootTotalPriceCart.setText("合计¥" + event.getPrice()); mFootTotalCountCart.setText("结算(" + event.getCount() + ")"); } @Override protected void onDestroy() { super.onDestroy(); EventBus.getDefault().unregister(this); shopCartP.detach(); } }
MyApppackage com.example.xiehaojia_20171219; import android.app.Application; import com.facebook.drawee.backends.pipeline.Fresco; /** * Created by lenovo on 2017/12/19. */ public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); Fresco.initialize(this); } }
RetrofitManagerpackage com.example.xiehaojia_20171219; import okhttp3.OkHttpClient; import retrofit2.Retrofit; import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; /** * Created by lenovo on 2017/12/19. */ public class RetrofitManager { private Retrofit mRetrofit; private String baseUrl; OkHttpClient client;//有关拦截器 private static RetrofitManager mRetrofitManager; private RetrofitManager(){} private RetrofitManager(String baseUrl,OkHttpClient client){ this.baseUrl=baseUrl; this.client=client;//有关拦截器 initRetrofit(); } public static synchronized RetrofitManager getInstance(String baseUrl,OkHttpClient client){//有关拦截器 if (mRetrofitManager == null){ mRetrofitManager = new RetrofitManager(baseUrl,client); } return mRetrofitManager; } private void initRetrofit() { mRetrofit = new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .client(client)//有关拦截器 .build(); } public <T> T setCreate(Class<T> reqServer){ return mRetrofit.create(reqServer); } }
WelcomeActivity
package com.example.xiehaojia_20171219; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.Toast; public class WelcomeActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcom); Button btn=(Button)findViewById(R.id.bt); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent =new Intent(WelcomeActivity.this,MainActivity.class); //启动 startActivity(intent); } }); } }
activity_main.xml
<?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:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/main_rlv" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="9"/> <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <CheckBox android:id="@+id/cart_foot_box" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:background="@null" android:text=" 全选" /> <TextView android:id="@+id/cart_foot_totalPrice" android:layout_height="match_parent" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:background="#ff5000" android:gravity="center_vertical" android:paddingLeft="20dp" android:text="结算()" android:textColor="#FFF" android:textSize="16dp" android:layout_width="120dp" /> <TextView android:id="@+id/cart_foot_totalCount" android:layout_height="match_parent" android:layout_alignParentTop="true" android:layout_toLeftOf="@id/cart_foot_totalPrice" android:layout_toStartOf="@id/cart_foot_totalPrice" android:gravity="center_vertical" android:text="合计" android:layout_width="80dp" /> </RelativeLayout> </LinearLayout>
activity_welcom.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="match_parent" android:layout_height="300dp" android:src="@mipmap/ic_launcher" /> <Button android:id="@+id/bt" android:text="加入购物车" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"/> </RelativeLayout>
custom_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="30dp" android:layout_height="30dp" android:text="-" android:background="#fff" android:id="@+id/jian" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="number" android:text="1" android:id="@+id/num"/> <Button android:layout_width="30dp" android:layout_height="30dp" android:background="#fff" android:text="+" android:id="@+id/jia"/> </LinearLayout>
rlv.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <CheckBox android:id="@+id/cart_box" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="10dp" /> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/cart_shopIv" android:layout_width="70dp" android:layout_height="70dp" android:layout_centerVertical="true" android:layout_toEndOf="@id/cart_box" android:layout_toRightOf="@id/cart_box" android:padding="10dp" android:src="@mipmap/ic_launcher" /> <TextView android:id="@+id/cart_delect" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="45dp" android:text="删除" android:textSize="20sp" /> <TextView android:id="@+id/cart_goodname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品名字" android:layout_above="@id/cart_shopIv" android:layout_alignLeft="@id/cart_shopIv" android:layout_alignStart="@id/cart_shopIv" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_centerVertical="true" android:layout_toRightOf="@id/cart_shopIv" android:layout_toEndOf="@id/cart_shopIv"> <TextView android:id="@+id/cart_goodprice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品价格" /> <LinearLayout android:layout_width="80dp" android:layout_height="20dp" android:layout_marginEnd="36dp" android:layout_marginRight="36dp" android:orientation="horizontal"> <ImageView android:id="@+id/cart_jian" android:layout_width="20dp" android:layout_height="wrap_content" android:src="@mipmap/jian" /> <TextView android:id="@+id/cart_num" android:layout_height="match_parent" android:gravity="center" android:text="1" android:textSize="15sp" android:layout_width="40dp" /> <ImageView android:id="@+id/cart_jia" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/jia" /> </LinearLayout> </LinearLayout> </RelativeLayout>