Android实现购物车及其他功能的角标
发布时间 - 2026-01-11 00:35:10 点击率:次1.先来张效果图
2.自定义一个角标工具类BottomBarView 。
**
* Created by Administrator on 2016/12/27.
* 角标工具类
*/
public class BottomBarView extends RelativeLayout {
private Context context;
private TextView bar_num;
private int count = 0;
public BottomBarView(Context context) {
this(context, null);
}
public BottomBarView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public BottomBarView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
RelativeLayout rl = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.bottom_bar_view, this, true);
bar_num = (TextView) rl.findViewById(R.id.bar_num);
bar_num.setVisibility(GONE);
}
public void add() {
bar_num.setVisibility(VISIBLE);
count++;
if (count < 100) {
bar_num.setText(count + "");
} else {
bar_num.setText("99+");
}
}
public void add(int n) throws Exception {
if(n<0){
throw new Exception(BottomBarView.class.getSimpleName()+" add(int n).The param must be a positive num");
}
bar_num.setVisibility(VISIBLE);
count += n;
if (count < 100) {
bar_num.setText(count + "");
} else {
bar_num.setText("99+");
}
}
public void delete() {
if (count == 0) {
bar_num.setVisibility(GONE);
} else {
count--;
if (count == 0) {
bar_num.setVisibility(GONE);
} else if (count > 0 && count < 100) {
bar_num.setVisibility(VISIBLE);
bar_num.setText(count + "");
} else {
bar_num.setVisibility(VISIBLE);
bar_num.setText("99+");
}
}
}
public void deleteAll() {
count = 0;
bar_num.setVisibility(GONE);
}
}
3.工具类的一个xml布局。
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <ImageView android:id="@+id/imggwc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toLeftOf="@+id/imggenduo" android:src="@drawable/chaoshi_shopping_nav_icon" /> <TextView android:id="@+id/bar_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="-12dp" android:layout_toRightOf="@+id/imggwc" android:background="@drawable/red_dot_bg" android:text="1" android:gravity="center" android:textColor="#FFFFFF" android:textSize="10dp" /> </RelativeLayout>
4.Activity的实现
public static BottomBarView fragment_bottom_bar;
fragment_bottom_bar = (BottomBarView) findViewById(R.id.fragment_bottom_bar);
//购物车数量角标数据
public static final void gwcsl() {
Map<String, String> map = new HashMap<String, String>();
map.put(ConstantUtil.TOKEN, SpUtil.get(ConstantUtil.TOKEN, ""));
NormalPostRequest npr = new NormalPostRequest(MyUrlUtils.getFullURL(BaseServerConfig.CSGWCSL),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
String code = response.getString("code");
if (BaseServerConfig.CODE_SUCCESS.equals(code)) {
//角标数
int jiaobiao = Integer.parseInt(response.getString("resultCode"));
try {
fragment_bottom_bar.deleteAll();
if (jiaobiao > 0) {
fragment_bottom_bar.add(jiaobiao);
} else {
fragment_bottom_bar.deleteAll();
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
}
} catch (JSONException e) {
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}, map);
BZApplication.getRequestQueue().add(npr);
}
5.activity的xml布局
<RelativeLayout android:id="@+id/csgwcdj" android:layout_width="45dp" android:layout_height="match_parent" android:layout_toLeftOf="@+id/relative"> <com.zjtd.bzcommunity.view.BottomBarView android:id="@+id/fragment_bottom_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" /> </RelativeLayout>
其实这个小功能很简单,只是你们想得太复杂。。。。。。。
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!
# android
# 角标
# 购物车角标
# 实现
# Android实现购物车功能
# Android实现的仿淘宝购物车demo示例
# Android实现仿淘宝购物车增加和减少商品数量功能demo示例
# Android把商品添加到购物车的动画效果(贝塞尔曲线)
# Android中实现淘宝购物车RecyclerView或LIstView的嵌套选择的逻辑
# Android仿外卖购物车功能
# Android制作简单的普通购物车
# Android仿饿了么加入购物车旋转控件自带闪转腾挪动画的按钮效果(实例详解)
# Android实现购物车添加物品的动画效果
# Android实现二级列表购物车功能
# 很简单
# 自定义
# 购物车
# 想得
# 先来
# 太复杂
# throws
# Exception
# setText
# param
# positive
# throw
# getSimpleName
# true
# void
# add
# id
# setVisibility
# lt
# VISIBLE
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
如何制作一个表白网站视频,关于勇敢表白的小标题?
Laravel如何安装Breeze扩展包_Laravel用户注册登录功能快速实现【流程】
Firefox Developer Edition开发者版本入口
如何在景安服务器上快速搭建个人网站?
Laravel怎么实现搜索高亮功能_Laravel结合Scout与Algolia全文检索【实战】
Python企业级消息系统教程_KafkaRabbitMQ高并发应用
Python文本处理实践_日志清洗解析【指导】
用v-html解决Vue.js渲染中html标签不被解析的问题
香港网站服务器数量如何影响SEO优化效果?
JS经典正则表达式笔试题汇总
如何在不使用负向后查找的情况下匹配特定条件前的换行符
Chrome浏览器标签页分组怎么用_谷歌浏览器整理标签页技巧【效率】
Laravel DB事务怎么使用_Laravel数据库事务回滚操作
Laravel如何升级到最新的版本_Laravel版本升级流程与兼容性处理
大学网站设计制作软件有哪些,如何将网站制作成自己app?
Laravel如何实现API速率限制?(Rate Limiting教程)
长沙企业网站制作哪家好,长沙水业集团官方网站?
利用vue写todolist单页应用
,怎么在广州志愿者网站注册?
Laravel模型事件有哪些_Laravel Model Event生命周期详解
Laravel如何生成和使用数据填充?(Seeder和Factory示例)
LinuxCD持续部署教程_自动发布与回滚机制
Laravel如何处理CORS跨域问题_Laravel项目CORS配置与解决方案
香港服务器选型指南:免备案配置与高效建站方案解析
如何用PHP快速搭建CMS系统?
JS去除重复并统计数量的实现方法
动图在线制作网站有哪些,滑动动图图集怎么做?
html5audio标签播放结束怎么触发事件_onended回调方法【教程】
公司门户网站制作流程,华为官网怎么做?
laravel怎么为应用开启和关闭维护模式_laravel应用维护模式开启与关闭方法
1688铺货到淘宝怎么操作 1688一键铺货到自己店铺详细步骤
Laravel如何实现数据导出到PDF_Laravel使用snappy生成网页快照PDF【方案】
Laravel如何处理文件上传_Laravel Storage门面实现文件存储与管理
制作企业网站建设方案,怎样建设一个公司网站?
公司门户网站制作公司有哪些,怎样使用wordpress制作一个企业网站?
黑客如何通过漏洞一步步攻陷网站服务器?
Laravel怎么配置不同环境的数据库_Laravel本地测试与生产环境动态切换【方法】
郑州企业网站制作公司,郑州招聘网站有哪些?
CSS3怎么给轮播图加过渡动画_transition加transform实现【技巧】
Laravel如何使用软删除(Soft Deletes)功能_Eloquent软删除与数据恢复方法
如何在浏览器中启用Flash_2025年继续使用Flash Player的方法【过时】
青岛网站建设如何选择本地服务器?
lovemo网页版地址 lovemo官网手机登录
家族网站制作贴纸教程视频,用豆子做粘帖画怎么制作?
Laravel如何实现用户注册和登录?(Auth脚手架指南)
千问怎样用提示词获取健康建议_千问健康类提示词注意事项【指南】
网站制作壁纸教程视频,电脑壁纸网站?
如何打造高效商业网站?建站目的决定转化率
Laravel如何处理异常和错误?(Handler示例)
如何用美橙互联一键搭建多站合一网站?

