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

首頁 > 系統 > Android > 正文

Android中使用TagFlowLayout制作動態添加刪除標簽

2019-10-22 18:31:53
字體:
來源:轉載
供稿:網友

效果圖

tagflowlayout,動態添加刪除標簽,android

簡單的效果圖(使用開源庫)[FlowLayout](“ https://github.com/hongyangAndroid/FlowLayout “)

步驟

導包

compile 'com.zhy:flowlayout-lib:1.0.3'<com.zhy.view.flowlayout.TagFlowLayout  android:id="@+id/id_flowlayout"  zhy:max_select="-1"  android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:padding="20dp"></com.zhy.view.flowlayout.TagFlowLayout>

初始化數據

private String[] mVals = new String[]    {"Hello", "Android", "Weclome Hi ", "Button", "TextView", "Hello",        "Android", "Weclome", "Button ImageView", "TextView", "Helloworld" }; arrTab = new ArrayList();  //添加一條數據用于添加標簽的替換  arrTab.add("tab");

設置TagFlowLayout的adapter

//設置adapter  adapter = new TagAdapter<String>(arrTab){    @Override    public View getView(FlowLayout parent, final int position, String s) {      System.out.println(position + "---" + (arrTab.size() - 1));      if (position == arrTab.size() - 1){        //設置最后一個添加標簽的布局        LinearLayout iv = (LinearLayout) LayoutInflater.from(SecondActivity.this).inflate( R.layout.iv,            mFlowLayout,false);        //如果點擊就添加元素并刷新adapter        iv.setOnClickListener(new View.OnClickListener() {          @Override          public void onClick(View v) {            int i = arrTab.size() - 1;            //將新加入的數據加到集合的最后一個位置,而原來的添加圖標會到 +1 的位置             arrTab.add(i , mVals[position]);            adapter.notifyDataChanged();          }        });        return iv ;      }else{      //正常標簽的布局        RelativeLayout tv = (RelativeLayout) LayoutInflater.from(SecondActivity.this).inflate( R.layout.tv,            mFlowLayout,false);        TextView viewById = (TextView) tv.findViewById(R.id.tv_name);        viewById.setText(s);        ImageView imageView = (ImageView) tv.findViewById(R.id.iv_delete);        imageView.setOnClickListener(new View.OnClickListener() {          @Override          public void onClick(View v) {            arrTab.remove(position);            System.out.println("我點擊的是" + position);            adapter.notifyDataChanged();          }        });        return tv;      }    }  };  mFlowLayout.setAdapter(adapter);

各種布局文件

iv<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="88dp"android:paddingTop="5dp"android:layout_height="40dp"><ImageView  android:layout_gravity="center"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:background="@drawable/bacs_btn_addbq"  />  </LinearLayout>tv<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="88dp"android:layout_height="wrap_content"><!--android:background="@drawable/tag_bg"--><TextView  android:id="@+id/tv_name"  android:layout_marginTop="7dp"   android:layout_width="80dp"  android:gravity="center"   android:layout_height="32dp"  android:background="@drawable/bg_tv"   android:text="我是唯愛"  android:textSize="13sp"   android:textColor="#FFF"></TextView><ImageView  android:id="@+id/iv_delete"  android:layout_alignParentRight="true"  android:layout_width="15dp"  android:layout_height="15dp"  android:src="@drawable/sm_ico_sounddel"  /></RelativeLayout>

以上所述是小編給大家介紹的Android中使用TagFlowLayout制作動態添加刪除標簽,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VEVB武林網網站的支持!


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武穴市| 安多县| 兴隆县| 色达县| 平邑县| 泾川县| 剑河县| 台安县| 青岛市| 新绛县| 绵竹市| 铜川市| 明星| 崇阳县| 扬中市| 磐安县| 尼木县| 夏津县| 成武县| 若尔盖县| 且末县| 正宁县| 静安区| 思茅市| 陆丰市| 宁明县| 铜山县| 措勤县| 卢龙县| 原平市| 深泽县| 鹤岗市| 安顺市| 南澳县| 咸阳市| 横山县| 曲沃县| 渑池县| 台湾省| 宝山区| 大城县|