国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android實(shí)現(xiàn)購物車及其他功能的角標(biāo)

2019-10-23 18:31:57
字體:
供稿:網(wǎng)友

1.先來張效果圖

android,角標(biāo),購物車角標(biāo),實(shí)現(xiàn)

2.自定義一個(gè)角標(biāo)工具類BottomBarView 。

** * Created by Administrator on 2016/12/27. * 角標(biāo)工具類 */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.工具類的一個(gè)xml布局。

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android/226977.html">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的實(shí)現(xiàn)

public static BottomBarView fragment_bottom_bar;fragment_bottom_bar = (BottomBarView) findViewById(R.id.fragment_bottom_bar);//購物車數(shù)量角標(biāo)數(shù)據(jù) 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)) { //角標(biāo)數(shù) 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>

其實(shí)這個(gè)小功能很簡單,只是你們想得太復(fù)雜。。。。。。。

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持VEVB武林網(wǎng)!


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 会昌县| 正镶白旗| 阿拉善盟| 手游| 湟中县| 虹口区| 博乐市| 定安县| 浮梁县| 奈曼旗| 八宿县| 容城县| 庄河市| 云梦县| 荣昌县| 滕州市| 庐江县| 外汇| 开远市| 绍兴县| 循化| 乐平市| 元谋县| 沛县| 博罗县| 北宁市| 麻江县| 大渡口区| 邯郸市| 虞城县| 芒康县| 从化市| 仙桃市| 宜春市| 青河县| 大足县| 新邵县| 麻城市| 玉山县| 大足县| 玉山县|