Android 仿京东【购物车】包含MVP.网络拦截器.防内存泄露...

一言不合就上图

这里写图片描述

首先在Manifest清单里面写权限:

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

然后是依赖:

    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.squareup.okhttp3:okhttp:3.9.0'
    compile 'com.google.code.gson:gson:2.8.2'
    //recyclerview
    compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.jcodecraeer:xrecyclerview:1.3.2'

然后在Values里写文件:

这里写图片描述

先是attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="AddDeleteViewStyle">
        <attr name="left_text" format="string"></attr>
        <attr name="right_text" format="string"></attr>
        <attr name="middle_text" format="string"></attr>
        <attr name="left_text_color" format="color"></attr>
    </declare-styleable>
</resources>

然后是dimens.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
</resources>

这里写图片描述

然后是activity_main.xml:

<?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="match_parent"
    android:orientation="vertical">
    <!--头布局-->
    <LinearLayout
        android:id="@+id/top_bar"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:background="#f7f7f7"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@android:color/transparent"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/back"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:layout_alignParentLeft="true"
                android:layout_gravity="center_vertical"
                android:padding="12dp"
                android:src="@mipmap/ic_launcher" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:minHeight="48dp"
                android:text="购物车"
                android:textColor="#1a1a1a"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/edit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="40dp"
                android:gravity="center"
                android:minHeight="48dp"
                android:text="编辑"
                android:textColor="#1a1a1a"
                android:textSize="14sp"
                android:visibility="visible" />
        </RelativeLayout>
    </LinearLayout>

    <ExpandableListView
        android:id="@+id/exListView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:childIndicator="@null"
        android:groupIndicator="@null" >
    </ExpandableListView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <CheckBox
            android:id="@+id/all_chekbox"
            android:layout_marginLeft="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="全选"/>
        <LinearLayout
            android:id="@+id/ll_info"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="4"
            >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginRight="20dp"
                android:layout_weight="1"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:gravity="right"
                    >
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:text="合计:"
                        android:textSize="18sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/total_price"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="¥0.00"
                        android:textColor="#f23232"
                        android:textSize="16sp"
                        android:textStyle="bold" />
                </LinearLayout>
                <TextView
                    android:id="@+id/total_number"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="共有商品:0件"
                    android:gravity="right"
                    android:textSize="16sp"
                    android:textStyle="bold" />
            </LinearLayout>
            <TextView
                android:id="@+id/tv_go_to_pay"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="3"
                android:background="#fd7a05"
                android:clickable="true"
                android:gravity="center"
                android:text="结算"
                android:textColor="#FAFAFA"

                />
        </LinearLayout>

    </LinearLayout>

</LinearLayout>

然后是activity_main3.xml:

<?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="match_parent"
    android:orientation="vertical">

    <com.jcodecraeer.xrecyclerview.XRecyclerView
        android:id="@+id/recy"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></com.jcodecraeer.xrecyclerview.XRecyclerView>
</LinearLayout>

然后是ex_child_item.xml:

避坑之自定义控件,要改成自己包下的控件名:
这里写图片描述

<?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="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal">
    <CheckBox
        an
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值