核心提示:仿京东购物车代码实现教程首先这篇文章主要就是实现一个仿京东购物车的类型,我用的MVP模式,主要实现的功能就是,全选,反选和删除,多的不说了,直接开粘吧。Retrofit的接口public interf...
仿京东购物车代码实现教程
首先这篇文章主要就是实现一个仿京东购物车的类型,我用的MVP模式,主要实现的功能就是,全选,反选和删除,多的不说了,直接开粘吧。
Retrofit的接口
public interface Inters { @GET("product/getCarts") Observable gets(@Query("uid") int uid); }</addbean>
我用的是Retrofit+Rxjava+OkHttp的结合框架请求的,Bean包这里我就不写了,下面直接开始MVP
V层
public interface IGouView { void onsuccer(AddBean bean);//成功的方法 }
M层
public class GouModel { ScuMod scuMod; public void setScuMod(ScuMod scuMod) { this.scuMod = scuMod; } //自己定义一个请求方法 public void Succes(){ OkHttpClient ok = new OkHttpClient.Builder() .build(); //请求数据 RetrofitUnitl.getInstance("https://120.27.23.105/",ok) .setCreate(Inters.class) .gets(98) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(AddBean bean) { scuMod.MScus(bean); Log.e("===========",bean.getData().get(0).getSellerName()); ; } }); } //定义一个接口 public interface ScuMod{ void MScus(AddBean bean); } }</addbean>
P层,我用的弱引用解绑,防止内存泄漏,可以不写。
public class GouPresenter implements GouModel.ScuMod { //弱引用解绑 WeakReference<igouview> view; GouModel model; public GouPresenter( IGouView view) { attach(view); model = new GouModel(); model.setScuMod(this); } @Override public void MScus(AddBean bean) { view.get().onsuccer(bean); } //我们在写一个方法拿到我们的请求 public void ShowPer(){ model.Succes(); } //绑定 public void attach(IGouView views){ view = new WeakReference(views); } //解绑方法 public void detach(){ view.clear(); } } </igouview>
自定义一个plusview
public class plusview extends LinearLayout { Button revserse,tianjian; EditText edittext; private int mcount = 1;//定义一个常量 用于购物车就入时默认显示为1 public plusview(Context context) { super(context); } public plusview(Context context, AttributeSet attributeSet){ super(context,attributeSet); //首先加载布局文件 View view = View.inflate(context, R.layout.plus_layout,null); //初始化控件 revserse = view.findViewById(R.id.revserse);//减号 tianjian = view.findViewById(R.id.tianjian);//加好 edittext = view.findViewById(R.id.edittext);//加号减号中间的输入框 //控件初始化玩之后 控件设置点击事件 revserse.setOnClickListener(new OnClickListener() { //减号的点击事件 @Override public void onClick(View view) { String trims = edittext.getText().toString().trim();//获取输入框的值去掉空格 int coun = Integer.valueOf(trims);//把从输入框的得到的值转换成整形 if (coun>1){ mcount = coun-1; edittext.setText(mcount+""); if (listener!=null){ listener.click(mcount); } } } }); //加号的点击事件 tianjian.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { String trim = edittext.getText().toString().trim();//获取输入框的值去掉空格 int coun = Integer.valueOf(trim)+1;//把从输入框的得到的值转换成整形 mcount = coun; edittext.setText(coun+""); if (listener!=null){ listener.click(coun); } } }); //输入框的点击事件 edittext.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { } }); addView(view); //添加布局 } public plusview(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public void setEditText(int num){ if(edittext != null){ edittext.setText(num+""); } } public ClickListener listener; public void setListener(ClickListener listener ){ this.listener=listener; } /** * 加减号的点击事件 */ public interface ClickListener{ public void click(int coun); } }
自定义中的布局
<!--?xml version="1.0" encoding="utf-8"?--> <linearlayout xmlns:android="https://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <button android:id="@+id/revserse" android:layout_width="20dp" android:layout_height="20dp" android:background="#FF00" android:text="-"> <edittext android:id="@+id/edittext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputtype="number" android:text="1"> </edittext></button><button android:id="@+id/tianjian" android:layout_width="20dp" android:layout_height="20dp" android:background="#FF00" android:text="+"> </button></linearlayout>
适配器
public class ShopAdapter extends RecyclerView.Adapter<shopadapter.viewholder>{ private Context context;//传入上下文 private List list;//bean包的集合 //存放商家的集合 private Map<string, string=""> map = new HashMap<>(); //有参构造 public ShopAdapter(Context context) { this.context = context; } /** * 添加数据并更新 */ public void add(AddBean bean) { //判段如果list是空的 if (this.list == null) { //那就把listNew出来 this.list = new ArrayList<>(); } //遍历商家 for (AddBean.DataBean shop : bean.getData()) { map.put(shop.getSellerid(), shop.getSellerName()); // 遍历商品 for (int i = 0; i < shop.getList().size(); i++) { this.list.add(shop.getList().get(i)); } } setFirst(this.list); //控制是否显示商家 notifyDataSetChanged();//更新数据 } /** * 设置数据源, 控制显示商家 * * @param list 这里把集合给setFirst这个方法就是要设置商品的显示与阴藏 */ private void setFirst(List list) { //这里判断 如果集合的字符大于0 你就默认显示一个商家 if (list.size() > 0) { list.get(0).setIsFirst(1); //这是默认显示商家 for (int i = 1; i < list.size(); i++) { //这是For循环把集合里的所有元素循出来 if (list.get(i).getSellerid() == list.get(i - 1).getSellerid()) { //如果俩个商品是同一个商家的那么就让这两个商品只显示一个商家 list.get(i).setIsFirst(2); } else { //如果不是 就两个都显示 list.get(i).setIsFirst(1); if (list.get(i).isItemSelected()) { list.get(i).setShopSelected(list.get(i).isItemSelected()); } } } } } /** * 加载布局文件 */ @Override public ShopAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = View.inflate(context, R.layout.adapter_layout, null); //添加到ViewHolder里 return new ViewHolder(view); } @Override public void onBindViewHolder(final ShopAdapter.ViewHolder holder, final int position) { // 显示商品图片 if (list.get(position).getIsFirst() == 1) { //显示商家 VISIBLE显示商品 holder.shop_checkbox.setVisibility(View.VISIBLE);//显示商家 holder.tv_item_shopcart_shopname.setVisibility(View.VISIBLE);//显示商家 holder.shop_checkbox.setChecked(list.get(position).isShopSelected()); // 显示商家的名称 // list.get(position).getSellerid() 取到商家的id // map.get()取到 商家的名称 holder.tv_item_shopcart_shopname.setText(map.get(String.valueOf(list.get(position).getSellerid()))); } else { holder.shop_checkbox.setVisibility(View.GONE);//隐藏商家 holder.tv_item_shopcart_shopname.setVisibility(View.GONE);//隐藏商家 } //控制 商品的 checkbox holder.item_checkbox.setChecked(list.get(position).isItemSelected()); //这是分割 由于接口中的图片是连这的所以必须要分割 String[] url = list.get(position).getImages().split("\\|"); // 从分割完之后返回的数组中设置所要显示的图片 // ImageLoader.getInstance().displayImage(url[0], holder.item_pic); Uri uri = Uri.parse(url[0]); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(uri) .setAutoPlayAnimations(true) .build(); holder.item_pic.setController(controller); //设置所要显示的文字 也是商家 holder.item_name.setText(list.get(position).getTitle()); //设置所要显示的价格 holder.item_price.setText(list.get(position).getPrice() + ""); //计算完所友的商品总价后在这设置显示 holder.plus_view_id.setEditText(list.get(position).getNum()); // 商家的checkbox 多选框 holder.shop_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { list.get(position).setShopSelected(holder.shop_checkbox.isChecked()); for (int i = 0; i < list.size(); i++) { if (list.get(position).getSellerid() == list.get(i).getSellerid()) { list.get(i).setItemSelected(holder.shop_checkbox.isChecked()); } } notifyDataSetChanged();//更新数据源 sum(list);//计算总价 } }); // 商品的checkbox 多选框 holder.item_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { list.get(position).setItemSelected(holder.item_checkbox.isChecked()); for (int i = 0; i < list.size(); i++) { for (int j = 0; j < list.size(); j++) { if (list.get(i).getSellerid() == list.get(j).getSellerid() && !list.get(j).isItemSelected()) { list.get(i).setShopSelected(false); break; } else { list.get(i).setShopSelected(true); } } } notifyDataSetChanged();//更新数据源 sum(list);//计算总价 } }); //删除的点击事件 holder.item_del.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //从集合中移除商家信息 list.remove(position); setFirst(list); notifyDataSetChanged();//更新数据 sum(list);//算总价 } }); //加减号 holder.plus_view_id.setListener(new plusview.ClickListener() { @Override public void click(int count) { list.get(position).setNum(count); notifyDataSetChanged();//更新适配器 sum(list);//计算总价 } }); } @Override public int getItemCount() { return list == null ? 0 : list.size();//三元运算符 } /** * 计算总价 * * @param list */ private void sum(List list) { int totalNum = 0; float totalMoney = 0.0f; boolean allCheck = true; for (int i = 0; i < list.size(); i++) { if (list.get(i).isItemSelected()) { totalNum += list.get(i).getNum(); totalMoney += list.get(i).getNum() * list.get(i).getPrice(); } else { allCheck = false; } } listener.setTotal(totalMoney + "", totalNum + "", allCheck); } public void selectAll(boolean cl) { for (int i = 0; i < list.size(); i++) { list.get(i).setShopSelected(cl); list.get(i).setItemSelected(cl); } notifyDataSetChanged(); sum(list); } public class ViewHolder extends RecyclerView.ViewHolder { View view; //item_del; plusview plus_view_id; CheckBox shop_checkbox, item_checkbox; TextView tv_item_shopcart_shopname, item_price, item_name, tv_item_shopcart_cloth_size; SimpleDraweeView item_pic; Button item_del; public ViewHolder(View itemView) { super(itemView); view = itemView.findViewById(R.id.view); item_del = itemView.findViewById(R.id.item_del); shop_checkbox = itemView.findViewById(R.id.shop_checkbox); item_checkbox = itemView.findViewById(R.id.item_checkbox); tv_item_shopcart_shopname = itemView.findViewById(R.id.tv_item_shopcart_shopname); item_price = itemView.findViewById(R.id.item_price); item_name = itemView.findViewById(R.id.item_name); tv_item_shopcart_cloth_size = itemView.findViewById(R.id.tv_item_shopcart_cloth_size); item_pic = itemView.findViewById(R.id.item_pic); plus_view_id = itemView.findViewById(R.id.plus_view_id); } } public UpdateUiListener listener; public void setListener(UpdateUiListener listener) { this.listener = listener; } //更新接口数据 public interface UpdateUiListener { public void setTotal(String total, String num, boolean allCheck); } }</addbean.databean.listbean></addbean.databean.listbean></string,></addbean.databean.listbean></shopadapter.viewholder>
适配器布局
<!--?xml version="1.0" encoding="utf-8"?--> <linearlayout xmlns:android="https://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:id="@+id/ll_shopcart_header" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <view android:id="@+id/view" android:layout_width="match_parent" android:layout_height="@dimen/margin_10dp" android:background="@color/background_color"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical"> <!-- 商店checkbox --> <checkbox android:id="@+id/shop_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingbottom="@dimen/margin_10dp" android:paddingleft="@dimen/margin_15dp" android:paddingright="@dimen/margin_15dp" android:paddingtop="@dimen/margin_10dp"> <!-- 商店名称 --> <textview android:id="@+id/tv_item_shopcart_shopname" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawablepadding="@dimen/padding_5dp" android:padding="@dimen/padding_10dp" android:text="宝儿家服装" android:textcolor="@color/cblack"> </textview></checkbox></linearlayout> </view></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"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal"> <!-- 商品 checkbox --> <checkbox android:id="@+id/item_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/margin_15dp"> <!-- 商品图片 --> <com.facebook.drawee.view.simpledraweeview android:id="@+id/item_pic" android:layout_width="60dp" android:layout_height="60dp" 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/item_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="¥185" android:textcolor="@color/main_red_text" android:textsize="@dimen/common_font_size_14"> <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginbottom="@dimen/margin_5dp" android:layout_margintop="@dimen/margin_5dp"> <textview android:id="@+id/item_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="颜色:黑色" android:textcolor="@color/cblack" android:textsize="@dimen/common_font_size_12"> <textview android:id="@+id/tv_item_shopcart_cloth_size" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="@dimen/margin_10dp" android:text="尺寸:XL" android:textcolor="@color/cblack" android:textsize="@dimen/common_font_size_12"> </textview></textview></linearlayout> <xinjiaqi.bwie.com.xinjiaqi20171211.zdy.plusview android:id="@+id/plus_view_id" android:layout_width="100dp" android:layout_height="wrap_content"> </xinjiaqi.bwie.com.xinjiaqi20171211.zdy.plusview> </textview></linearlayout> <view android:layout_width="@dimen/margin_1dp" android:layout_height="match_parent" android:layout_marginbottom="@dimen/padding_10dp" android:layout_margintop="@dimen/padding_10dp" android:background="@color/splitline_color"> <button android:id="@+id/item_del" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/margin_20dp" android:text="删除" android:background="#f0f0f0"> <view android:layout_width="match_parent" android:layout_height="@dimen/margin_1dp" android:background="@color/background_color"> </view></button></view></com.facebook.drawee.view.simpledraweeview></checkbox></linearlayout></view></linearlayout></linearlayout></linearlayout>
主方法
public class MainActivity extends AppCompatActivity implements IGouView { RecyclerView third_recyclerview; LinearLayout third_pay_linear; CheckBox third_allselect; Button third_submit; TextView edittext, third_totalnum, third_totalprice; private GouPresenter presenter; private ShopAdapter adapter; AddBean shopBean; List list = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //找控控件 third_recyclerview = (RecyclerView) findViewById(R.id.third_recyclerview); third_pay_linear = (LinearLayout) findViewById(R.id.third_pay_linear); third_allselect = (CheckBox) findViewById(R.id.third_allselect); third_totalprice = (TextView) findViewById(R.id.third_totalprice); edittext = (TextView) findViewById(R.id.edittext); third_totalnum = (TextView) findViewById(R.id.third_totalnum); third_submit = (Button) findViewById(R.id.third_submit); //调用P层 presenter = new GouPresenter(this); presenter.ShowPer(); //线性布局 LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); third_recyclerview.setLayoutManager(manager); //绑定适配器 adapter = new ShopAdapter(MainActivity.this); third_recyclerview.setAdapter(adapter); third_allselect.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { adapter.selectAll(third_allselect.isChecked()); } }); adapter.setListener(new ShopAdapter.UpdateUiListener() { @Override public void setTotal(String total, String num, boolean allCheck) { third_allselect.setChecked(allCheck); third_totalnum.setText(num); third_totalprice.setText(total); } }); } @Override public void onsuccer(AddBean bean) { adapter.add(bean); } //解绑 @Override protected void onDestroy() { super.onDestroy(); presenter.detach(); } } </addbean>
主方法布局
<!--?xml version="1.0" encoding="utf-8"?--> <linearlayout xmlns:android="https://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:id="@+id/third_pay_linear" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0" android:background="#FFFFFF" android:gravity="center_vertical" android:orientation="horizontal"> <checkbox android:id="@+id/third_allselect" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="@dimen/margin_10dp" android:checked="false" android:drawablepadding="@dimen/padding_5dp" android:text="全选"> <linearlayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical"> <textview android:id="@+id/third_totalprice" android:layout_width="200dp" android:layout_height="wrap_content" android:paddingleft="@dimen/padding_10dp" android:paddingtop="@dimen/padding_10dp" android:text="总价:" android:textcolor="@color/cblack" android:textsize="@dimen/common_font_size_16"> <textview android:id="@+id/third_totalnum" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingbottom="@dimen/padding_10dp" android:paddingleft="@dimen/padding_10dp" android:text="共0件商品" android:textcolor="@color/cblack" android:textsize="@dimen/common_font_size_14"> </textview></textview></linearlayout> <button android:id="@+id/third_submit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginright="@dimen/margin_10dp" android:paddingbottom="@dimen/padding_10dp" android:paddingleft="@dimen/margin_30dp" android:paddingright="@dimen/margin_30dp" android:paddingtop="@dimen/padding_10dp" android:text="去结算" android:textcolor="#000000"> </button></checkbox></linearlayout></android.support.v7.widget.recyclerview></linearlayout>
最后我们需要配置values下面的文件
colors.xml
<!--?xml version="1.0" encoding="utf-8"?--> <resources> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color> <color name="cwhite">#FFFFFF</color> <color name="title_bg">#FDE23D</color> <color name="tab_bg">#FFFFFF</color> <color name="tab_normal_textcolor">#373737</color> <color name="tab_selected_textcolor">#FDE23D</color> <color name="coffer">#442509</color> <color name="pressed_icon_color">#e53e42</color> <color name="background_color">#f6f6f6</color> <color name="main_red_text">#e53e42</color> <dimen name="padding_20dp">20dp</dimen> <color name="splitline_color">#dddddd</color> <color name="cblack">#000000</color> </resources>
diment.xml
<!--?xml version="1.0" encoding="utf-8"?--> <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="margin_10dp">10dp</dimen> <dimen name="padding_5dp">5dp</dimen> <dimen name="padding_10dp">10dp</dimen> <dimen name="common_font_size_16">16sp</dimen> <dimen name="common_font_size_14">14sp</dimen> <dimen name="height_200dp">200dp</dimen> <dimen name="margin_30dp">30dp</dimen> <dimen name="margin_15dp">15dp</dimen> <dimen name="margin_1dp">1dp</dimen> <dimen name="margin_5dp">5dp</dimen> <dimen name="common_font_size_12">12sp</dimen> <dimen name="padding_2dp">2dp</dimen> <dimen name="margin_20dp">20dp</dimen> </resources>
还有在drawable下面创建三个view
view.xml
<!--?xml version="1.0" encoding="utf-8"?--> <vector xmlns:android="https://schemas.android.com/apk/res/android" android:width="108dp" android:height="108dp" android:viewportheight="108" android:viewportwidth="108"> <path android:fillcolor="#26A69A" android:pathdata="M0,0h108v108h-108z"> <path android:fillcolor="#00000000" android:pathdata="M9,0L9,108" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M19,0L19,108" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M29,0L29,108" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M39,0L39,108" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M49,0L49,108" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M59,0L59,108" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M69,0L69,108" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M79,0L79,108" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M89,0L89,108" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M99,0L99,108" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M0,9L108,9" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M0,19L108,19" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M0,29L108,29" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M0,39L108,39" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M0,49L108,49" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M0,59L108,59" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M0,69L108,69" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M0,79L108,79" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M0,89L108,89" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M0,99L108,99" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M19,29L89,29" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M19,39L89,39" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M19,49L89,49" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M19,59L89,59" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M19,69L89,69" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M19,79L89,79" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M29,19L29,89" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M39,19L39,89" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M49,19L49,89" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M59,19L59,89" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M69,19L69,89" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> <path android:fillcolor="#00000000" android:pathdata="M79,19L79,89" android:strokecolor="#33FFFFFF" android:strokewidth="0.8"> </path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></path></vector>
view1.xml
<!--?xml version="1.0" encoding="utf-8"?--> <shape xmlns:android="https://schemas.android.com/apk/res/android"> <corners android:radius="@dimen/height_200dp"></corners> <stroke android:color="@color/background_color" android:width="1dp"></stroke> </shape>
view2.xml
<shape xmlns:android="https://schemas.android.com/apk/res/android"> <corners android:radius="@dimen/height_200dp"></corners> <solid android:color="@color/pressed_icon_color"></solid> </shape>
代码完事以后,记得在清单文件中加入权限
<uses-permission android:name="android.permission.INTERNET"> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission></uses-permission></uses-permission>
依赖就不导了