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

Android中使用TagFlowLayout制作動(dòng)態(tài)添加刪除標(biāo)簽

 更新時(shí)間:2017年07月21日 09:21:37   作者:唯愛丶?jí)? 
這篇文章主要介紹了Android中使用TagFlowLayout制作動(dòng)態(tài)添加刪除標(biāo)簽的步驟詳解,需要的朋友參考下吧

效果圖

這里寫圖片描述

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

步驟

導(dǎo)包

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>

初始化數(shù)據(jù)

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

設(shè)置TagFlowLayout的adapter

//設(shè)置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){
        //設(shè)置最后一個(gè)添加標(biāo)簽的布局
        LinearLayout iv = (LinearLayout) LayoutInflater.from(SecondActivity.this).inflate( R.layout.iv,
            mFlowLayout,false);
        //如果點(diǎn)擊就添加元素并刷新adapter
        iv.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            int i = arrTab.size() - 1;
            //將新加入的數(shù)據(jù)加到集合的最后一個(gè)位置,而原來的添加圖標(biāo)會(huì)到 +1 的位置 
            arrTab.add(i , mVals[position]);
            adapter.notifyDataChanged();
          }
        });
        return iv ;
      }else{
      //正常標(biāo)簽的布局
        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("我點(diǎn)擊的是" + 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
<RelativeLayout
xmlns: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制作動(dòng)態(tài)添加刪除標(biāo)簽,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論

治县。| 石泉县| 彩票| 湘西| 山阳县| 资阳市| 德昌县| 新津县| 绥滨县| 绥德县| 三门峡市| 鲜城| 兰西县| 白玉县| 玉树县| 邹平县| 高雄县| 海淀区| 石狮市| 涟源市| 开远市| 措勤县| 大宁县| 汾西县| 长岭县| 三门县| 马鞍山市| 开平市| 仁怀市| 盈江县| 比如县| 清原| 建昌县| 平遥县| 锡林郭勒盟| 驻马店市| 安康市| 桂平市| 临清市| 乌兰浩特市| 长春市|