使用recyclerView,GridView来实现动态显示商品选择规格

本文介绍如何在电商项目中实现商品选择规格功能,利用RecyclerView和GridView动态展示不同商品的尺寸、颜色等属性。通过点击购物车按钮弹出PopupWindow,布局包含商品信息和属性选择。详细讲解实现思路,并提供相关布局文件和代码下载链接。
摘要由CSDN通过智能技术生成

使用recyclerView,GridView来实现动态显示商品选择规格

        在很多的电商的项目当中都有添加购物车的这项功能,而添加购物车功能必不可少的就是选择商品的规格,比如说,尺寸、颜色、口味等等,如果每个商品只有一个规格,那就非常好办,但是由于商品的属性的多样性,也就意味着商品属性的不确定性,所以在编写选择商品规格的时候就不能固定商品属性的选择。由于本人在android方面也是菜鸟一只,当项目需要的时候也是上网去搜索大牛写的关于商品选择规格的实现,以下是我上网搜索的一篇博客:http://blog.csdn.net/zxw136511485/article/details/50357354,本篇文章是在此文章的基础上进行改写的,感谢这位博主的分享。

好了,接下来就进入正题了,先说说我的实现的思路,首先一般的商品选择规格的界面都是如下图所示:


一般都是点击购物车按钮,popupWindow来进行由下方向上方弹出,而在popupWindow的布局中一般是有商品名称,图片,以及商品的属性的选择,这里我采用recyclerView加GridView实现,也就是recyclerView中的每个item项由一个TextView和一个GridView实现。

首先是布局文件:

activity_recyler_sku.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.zqy.myselectorspec.RecylerSkuActivity">
    <LinearLayout
        android:id="@+id/ll_botttom"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:weightSum="2" >

        <Button
            android:id="@+id/id_put_cart"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#ff9100"
            android:text="加入购物车"
            android:textColor="#fff"
            />
        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#ff5001"
            android:text="立即购买"
            android:textColor="#fff"
            />
    </LinearLayout><pre name="code" class="plain">

 

gridview_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:padding="0dp" >

    <LinearLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@xml/shape1"
        android:gravity="center" >

        <TextView
            android:id="@+id/ItemText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView01"
            android:textSize="15sp" >
        </TextView>
    </LinearLayout>

</LinearLayout>

recycler_item_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="title"
        android:textSize="18sp"
        android:padding="12dp"
        />
    <com.zqy.myselectorspec.MyGridView
        android:id="@+id/gv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:cacheColorHint="#00000000"
        android:horizontalSpacing="10dp"
        android:listSelector="#00000000"
        android:numColumns="3"
        android:padding="5dp"
        android:scrollbars="none"
        android:verticalSpacing="10dp" />
</Li
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值