//activity_main
<?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:orientation="vertical" tools:context="com.bwie.test.yuekao20171221.MainActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="50dp"> <ImageView android:layout_width="25dp" android:layout_height="25dp" android:src="@drawable/icon_back" android:layout_centerVertical="true" android:layout_marginLeft="10dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="购物车" android:layout_centerInParent="true"/> <TextView android:layout_width="match_parent" android:layout_height="0.1dp" android:layout_alignParentBottom="true" android:background="#000000"/> </RelativeLayout> <ExpandableListView android:id="@+id/cart_list" android:groupIndicator="@null" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> </ExpandableListView> <TextView android:layout_width="match_parent" android:layout_height="0.1dp" android:background="#000000"/> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp"> <LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:gravity="center_vertical"> <CheckBox android:id="@+id/all_check" android:layout_width="25dp" android:layout_height="25dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="全选/反选"/> <TextView android:layout_marginLeft="20dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="总价:¥" android:textColor="#FF0000"/> <TextView android:id="@+id/total_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0.00" android:textColor="#FF0000"/> </LinearLayout> <Button android:id="@+id/clearing" android:layout_width="80dp" android:layout_height="match_parent" android:text="去结算(0)" android:textColor="#FFFFFF" android:background="@drawable/cart_btn_bg"/> </LinearLayout> </LinearLayout>
//activity_order_list
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" android:orientation="vertical" tools:context=".OrderListActivity"> <RelativeLayout android:id="@+id/parent" android:layout_width="match_parent" android:layout_height="50dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="订单列表" android:layout_centerInParent="true"/> <ImageView android:id="@+id/status" android:layout_width="25dp" android:layout_height="25dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:src="@drawable/lv_icon" android:layout_marginRight="10dp"/> <TextView android:layout_width="match_parent" android:layout_height="0.1dp" android:layout_alignParentBottom="true" android:background="#000000"/> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp"> <TextView android:id="@+id/unpaid" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:gravity="center" android:text="待支付"/> <TextView android:layout_width="1dp" android:layout_height="match_parent" android:background="#000000"/> <TextView android:id="@+id/paid" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:gravity="center" android:text="已支付"/> <TextView android:layout_width="1dp" android:layout_height="match_parent" android:background="#000000"/> <TextView android:id="@+id/canceled" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:gravity="center" android:text="已取消"/> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="0.1dp" android:background="#000000"/> <android.support.v7.widget.RecyclerView android:id="@+id/recy" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v7.widget.RecyclerView> </LinearLayout>
//cart_child
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="100dp" android:gravity="center_vertical"> <CheckBox android:id="@+id/child_check" android:layout_width="25dp" android:layout_height="25dp" /> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/image" android:layout_marginLeft="10dp" android:layout_width="80dp" android:layout_height="80dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:orientation="vertical"> <TextView android:id="@+id/child_title" android:layout_width="match_parent" android:layout_height="40dp" android:gravity="center_vertical" android:maxLines="1"/> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp"> <TextView android:id="@+id/price_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="优惠价:¥" android:textColor="#FF0000" android:layout_centerVertical="true"/> <TextView android:layout_toRightOf="@+id/price_text" android:id="@+id/bargain_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0.00" android:textColor="#FF0000" android:layout_centerVertical="true"/> <com.bwie.test.yuekao20171221.custom.NumberAddSubView android:id="@+id/number_view" android:layout_alignParentRight="true" android:layout_width="100dp" android:layout_height="25dp" app:value="1" app:minValue="1" app:maxValue="200" android:layout_centerVertical="true"> </com.bwie.test.yuekao20171221.custom.NumberAddSubView> </RelativeLayout> </LinearLayout> </LinearLayout>
//cart_group
<?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="40dp" android:orientation="horizontal" android:gravity="center_vertical"> <CheckBox android:id="@+id/group_check" android:layout_width="25dp" android:layout_height="25dp" /> <TextView android:id="@+id/group_name" android:layout_marginLeft="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
//layout_pop
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="40dp" android:layout_height="92dp" android:orientation="vertical"> <TextView android:id="@+id/unpaid" android:layout_width="match_parent" android:layout_height="30dp" android:text="待支付" android:textSize="12sp" android:gravity="center"/> <TextView android:layout_width="match_parent" android:layout_height="1dp" android:background="#000000"/> <TextView android:id="@+id/paid" android:layout_width="match_parent" android:layout_height="30dp" android:text="已支付" android:textSize="12sp" android:gravity="center"/> <TextView android:layout_width="match_parent" android:layout_height="1dp" android:background="#000000"/> <TextView android:id="@+id/canceled" android:layout_width="match_parent" android:layout_height="30dp" android:text="已取消" android:textSize="12sp" android:gravity="center"/> </LinearLayout>
//number_add_sub_view
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="100dp" android:layout_height="25dp" android:background="@drawable/selector_number_add_sub" android:orientation="horizontal"> <Button android:id="@+id/btn_sub" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:background="@drawable/bg_btn_style_white" android:text="-" android:textColor="#000000" android:textSize="14sp" /> <TextView android:id="@+id/tv_num" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:gravity="center" android:minWidth="100dp" android:text="1" /> <Button android:id="@+id/btn_add" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:background="@drawable/bg_btn_style_white" android:text="+" android:textColor="#000000" android:textSize="14sp" /> </LinearLayout>
//order_recy_item
<?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="120dp" android:orientation="vertical" android:paddingLeft="20dp" android:paddingRight="20dp"> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp"> <TextView android:id="@+id/order_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="标题" android:layout_centerVertical="true"/> <TextView android:id="@+id/order_status" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:text="待"/> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp"> <TextView android:id="@+id/order_price_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="价格:¥" android:textColor="#FF0000" android:layout_centerVertical="true"/> <TextView android:id="@+id/order_price" android:layout_toRightOf="@+id/order_price_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="0.00" android:textColor="#FF0000"/> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp"> <TextView android:id="@+id/time_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="创建时间:" android:layout_centerVertical="true"/> <TextView android:id="@+id/order_create_time" android:layout_toRightOf="@+id/time_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2017" android:layout_centerVertical="true"/> <Button android:id="@+id/order_btn" android:layout_width="60dp" android:layout_height="20dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:text="取消订单" android:textSize="8sp" android:background="@drawable/order_btn_bg"/> </RelativeLayout> </LinearLayout>
drawable文件夹下//bg_btn_style_white.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="false"> <shape android:shape="rectangle"> <corners android:radius="2.0dp" /> <solid android:color="#7fd8d8d8" /> <stroke android:width="1.0dp" android:color="#dddddd" /> </shape> </item> <item android:state_pressed="true"> <shape android:shape="rectangle"> <corners android:radius="2.0dp" /> <solid android:color="#ffd8d8d8" /> <stroke android:width="1.0dp" android:color="#ddd" /> </shape> </item> <item> <shape android:shape="rectangle"> <corners android:radius="2.0dp" /> <solid android:color="#ffffff" /> <stroke android:width="1.0dp" android:color="#dddddd" /> </shape> </item> </selector>
//cart_btn_bg
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FF0000"/> <stroke android:color="#000000" android:width="0.1dp"/> </shape>
//order_btn_bg
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FFFFFF"/> <stroke android:color="#000000" android:width="0.1dp"/> <corners android:radius="5dp"/> </shape>
//selector_number_add_sub
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="2dp" /> <stroke android:width="1dp" android:color="#dddddd" /> <solid android:color="#FFFFFF" /> </shape>
values文件夹下//attrs.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="NumberAddSubView"> <attr name="value" format="integer|reference"/> <attr name="minValue" format="integer|reference"/> <attr name="maxValue" format="integer|reference"/> <attr name="btnAddBackground" format="reference"/> <attr name="btnSubBackground" format="reference"/> <attr name="textViewBackground" format="reference"/> </declare-styleable> </resources>
//添加权限
<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"/> <application android:name=".application.RookieApplication" <activity android:name=".MainActivity"> </activity> <activity android:name=".OrderListActivity"/> </application>
//添加依赖
compile 'com.android.support:appcompat-v7:26.0.0-alpha1' testCompile 'junit:junit:4.12' compile 'com.android.support.test:runner:0.5' compile 'com.android.support.test.espresso:espresso-core:2.2.2' compile 'com.google.code.gson:gson:2.8.2' compile 'com.squareup.okhttp3:okhttp:3.6.0' compile 'com.squareup.okio:okio:1.11.0' compile 'com.facebook.fresco:fresco:0.11.0' compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'