AutoLabelUi使用简记

本文介绍了AutoLabelUI的布局和基本代码使用,提供了一个项目的链接和Demo下载,适合想了解和使用AutoLabelUI的读者。

转载请注明出处:
http://blog.youkuaiyun.com/user11223344abc?viewmode=contents
出自【蛟-blog】

本文只讨论如何使用,有兴趣朋友的可以去原作者项目地址下看看

这里贴出项目地址:
https://github.com/DavidPizarro/AutoLabelUI

布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:autolabel="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_zj_test"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.dpizarro.libraries.autolabelui.ZjTestActivity">

    <com.dpizarro.autolabel.library.AutoLabelUI
        android:id="@+id/label_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        autolabel:icon_cross="@drawable/cross"
        autolabel:label_background_res="@color/default_background_label"
        autolabel:label_clickable="true"
        autolabel:max_labels="10"
        autolabel:show_cross="true"
        autolabel:text_color="@android:color/white"
        autolabel:text_size="@dimen/label_title_size" />

</RelativeLayout>

基本代码

package com.dpizarro.libraries.autolabelui;

import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.dpizarro.autolabel.library.AutoLabelUI;
import com.dpizarro.autolabel.library.Label;

import java.util.ArrayList;
import java.util.List;

public class ZjTestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zj_test);

        AutoLabelUI autoLabelUI = (AutoLabelUI) findViewById(R.id.label_view);
        autoLabelUI.setBackgroundResource(R.drawable.round_corner_background);//设置圆角风格

        showLabel(autoLabelUI);

        autoLabelUI.setOnLabelClickListener(new AutoLabelUI.OnLabelClickListener() {
            @Override
            public void onClickLabel(Label labelClicked) {
                Toast.makeText(ZjTestActivity.this, labelClicked.getText(), Toast.LENGTH_SHORT).show();
            }
        });

        autoLabelUI.setOnRemoveLabelListener(new AutoLabelUI.OnRemoveLabelListener() {
            @Override
            public void onRemoveLabel(Label removedLabel, int position) {
                Toast.makeText(ZjTestActivity.this, removedLabel.getText() + "被删除了", Toast.LENGTH_SHORT).show();
            }
        });

    }

    private void showLabel(AutoLabelUI autoLabelUI) {
        List<Person> testDatas = getData();

        for (int i = 0; i < testDatas.size(); i++) {
            autoLabelUI.addLabel(testDatas.get(i).getName());
        }
    }

    public List<Person> getData() {
        List<Person> testDatas = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            testDatas.add(new Person("MR__" + i, String.valueOf(i), i, false));
        }
        return testDatas;
    }
}

本文Demo:
点击下载
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FkixP9BF-1574311288201)(https://github.com/zj614android/picsLink/blob/master/zjtestlabel.png?raw=true)]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值