我们安卓的电商类项目中 购物车的身影特别常见 那我们如何去进行实现一个简单的购物车呢?
接下来带大家看一下
首先展示一下效果图

那么如图所示 就是我们完成的一个购物车
首先做这个展示的页面
接下来就是上代码了
布局文件
<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=".MainActivity">
//一个二级列表
<ExpandableListView
android:id="@+id/elc_show_main"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#fff">
</ExpandableListView>
//一个布局里面存放 CheckBox 以及总价
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<CheckBox
android:id="@+id/cb_allCheck_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="全选/反选"
android:textColor="#000" />
<TextView
android:id="@+id/btn_allPrice_main"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="价格"
android:textColor="@android:color/holo_red_dark"
android:textSize="20

本文介绍如何在Android应用中实现一个简单的购物车展示页面。通过展示效果图,并逐步讲解布局文件、资源ID的获取、数据请求以及适配器的使用,包括父布局、子布局、自定义View的创建,帮助开发者理解购物车页面的实现过程。
最低0.47元/天 解锁文章
2705

被折叠的 条评论
为什么被折叠?



