最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2017年04月10日 10:39:59   作者:瞳瞳色丶輕煙  
本文主要介紹了Android實(shí)現(xiàn)購物車及其他功能的角標(biāo)的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來看下吧

1.先來張效果圖

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="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)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

  • Android ListView自動(dòng)顯示隱藏布局的實(shí)現(xiàn)方法

    Android ListView自動(dòng)顯示隱藏布局的實(shí)現(xiàn)方法

    這篇文章主要介紹了Android ListView自動(dòng)顯示隱藏布局的實(shí)現(xiàn)方法的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-09-09
  • Android使用個(gè)推實(shí)現(xiàn)三方應(yīng)用的推送功能

    Android使用個(gè)推實(shí)現(xiàn)三方應(yīng)用的推送功能

    這篇文章主要為大家詳細(xì)介紹了Android使用個(gè)推實(shí)現(xiàn)三方應(yīng)用的推送功能,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Flutter質(zhì)感設(shè)計(jì)之模態(tài)底部面板

    Flutter質(zhì)感設(shè)計(jì)之模態(tài)底部面板

    這篇文章主要為大家詳細(xì)介紹了Flutter質(zhì)感設(shè)計(jì)之模態(tài)底部面板,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • Android顯示GIF圖片實(shí)例代碼

    Android顯示GIF圖片實(shí)例代碼

    這篇文章主要介紹了Android顯示GIF圖片實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-05-05
  • Android如何在原生App中嵌入Flutter

    Android如何在原生App中嵌入Flutter

    這篇文章主要介紹了Android如何在原生App中嵌入Flutter,幫助大家更好的理解和學(xué)習(xí)Android開發(fā),感興趣的朋友可以了解下
    2021-03-03
  • Android操作系統(tǒng)的架構(gòu)設(shè)計(jì)分析

    Android操作系統(tǒng)的架構(gòu)設(shè)計(jì)分析

    這篇文章主要介紹了Android操作系統(tǒng)的架構(gòu)設(shè)計(jì)分析,Android系統(tǒng)架構(gòu)分為Linux內(nèi)核驅(qū)動(dòng)、C/C ++框架、Java框架、Java應(yīng)用程序,本文分別講解了它的作用,需要的朋友可以參考下
    2015-06-06
  • Android 10 適配攻略小結(jié)

    Android 10 適配攻略小結(jié)

    這篇文章主要介紹了Android 10 適配攻略小結(jié),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • Android后端服務(wù)器的搭建方法

    Android后端服務(wù)器的搭建方法

    本篇文章主要介紹了Android后端服務(wù)器的搭建方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-07-07
  • 通俗易通講解Android藍(lán)牙鍵值適配

    通俗易通講解Android藍(lán)牙鍵值適配

    這篇文章介紹了Android藍(lán)牙鍵值適配的方法,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值。需要的朋友可以收藏下,方便下次瀏覽觀看
    2021-12-12
  • android 獲取APP的唯一標(biāo)識(shí)applicationId的實(shí)例

    android 獲取APP的唯一標(biāo)識(shí)applicationId的實(shí)例

    下面小編就為大家分享一篇android 獲取APP的唯一標(biāo)識(shí)applicationId的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02

最新評(píng)論

湟源县| 大方县| 深州市| 镇远县| 分宜县| 禹州市| 秀山| 夏邑县| 阿城市| 安陆市| 青龙| 宁陵县| 五华县| 抚宁县| 白山市| 武宁县| 东平县| 申扎县| 舞钢市| 崇州市| 扶风县| 宜兰县| 镇赉县| 峨边| 岚皋县| 岑巩县| 无棣县| 鹤岗市| 塘沽区| 手游| 海口市| 茌平县| 平安县| 全南县| 肇东市| 揭东县| 连州市| 东乌| 灵山县| 满城县| 南陵县|