一言不合就上图
首先在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