重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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"?>
4.Activity的实现
public static BottomBarView fragment_bottom_bar; fragment_bottom_bar = (BottomBarView) findViewById(R.id.fragment_bottom_bar); //购物车数量角标数据 public static final void gwcsl() { Mapmap = new HashMap (); map.put(ConstantUtil.TOKEN, SpUtil.get(ConstantUtil.TOKEN, "")); NormalPostRequest npr = new NormalPostRequest(MyUrlUtils.getFullURL(BaseServerConfig.CSGWCSL), new Response.Listener () { @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布局
其实这个小功能很简单,只是你们想得太复杂。。。。。。。
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持创新互联!