转载请注明出处:
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)]
本文介绍了AutoLabelUI的布局和基本代码使用,提供了一个项目的链接和Demo下载,适合想了解和使用AutoLabelUI的读者。
1262

被折叠的 条评论
为什么被折叠?



