欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

效果圖

這里寫圖片描述

簡單的效果圖(使用開源庫)[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)簽,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論