AndroidTagView 云标签

AndroidTagView云标签

Build Status Android Arsenal

  这是一个Android的云标签示例,这个View支持标签,点击,长按弹出删除对话框,拖拽排序,当前行超出屏幕宽度自动挤压到第二行……

截图

这里写图片描述
这里写图片描述

Usage使用

步骤 1

  向build.gradle 添加依赖:

dependencies {
    compile 'co.lujun:androidtagview:1.1.1'
}

步骤 2

  在你的布局文件中使用AndroidTagView,你可以为AndroidTaghView自定义属性。

<co.lujun.androidtagview.TagContainerLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="0dp"
    android:padding="10dp"
    app:container_enable_drag="false"
    app:horizontal_interval="10dp"
    app:vertical_interval="10dp"
    app:tag_clickable="true"
    app:tag_theme="pure_teal" />

步骤 3

  在你的代码中使用AndroidTagView:

TagContainerLayout mTagContainerLayout = (TagContainerLayout) findViewById(R.id.tagcontainerLayout);
mTagContainerLayout.setTags(List<String> tags);

  现在,你已经成功的创建了TagView了。下文会展示更多有用的自定义属性:

属性

nameformatdescription
vertical_intervaldimension垂直间隔,默认是5dp
horizontal_intervaldimension水平间隔,默认是5dp
container_border_widthdimensionTagContainerLayout的边框粗细,默认是0.5dp
container_border_radiusdimensionTagContainerLayout的边框圆角,默认是10.0dp
container_border_colorcolorTagContainerLayout 的边框颜色(默认是#22FF0000)
container_background_colorcolorTagContainerLayout的背景颜色(默认是#11FF0000)
container_enable_dragbooleanTagView是否可拖拽(默认是false)
container_drag_sensitivityfloatTagView拖拽灵敏度(默认是1.0f, normal)
container_gravityenumTagContainerLayout gravity的Gravity属性
container_max_linesintegerTagContainerLayout的最大行数(默认是0, 自动增长)
tag_border_widthdimensionTagView的边框狂赌(默认是0.5dp)
tag_corner_radiusdimensionTagView的边框圆角(默认是15.0dp)
tag_horizontal_paddingdimensionTagView的水平padding属性值, 包括left和right的padding属性值(左右的padding值是相同的, 默认是10dp)
tag_vertical_paddingdimensionTagView的垂直padding属性值, 包括top和bottom的padding属性值(上下的padding值是相同的, 默认是8dp)
tag_text_sizedimensionTagView的文字大小(默认是14sp)
tag_bd_distancedimension基线和 descent之间的距离(默认是2.75dp)
tag_text_colorcolorTagView的文字颜色(默认是 #FF666666)
tag_border_colorcolorTagView边框颜色(默认是 #88F44336)
tag_background_colorcolorTagView背景颜色(默认是#33F44336)
tag_max_lengthintegerTagView可以占到的最大长度(默认的最大长度是23)
tag_clickablebooleanTagView是否可点击(默认是不可点击unclickable)
tag_themeenumTagView的 主题
tag_text_directionenumTagView的字体方向
tag_ripple_colorcolor涟漪效应色彩 (默认是#EEEEEE)
tag_ripple_alphainteger涟漪效应的Alpha值 (Alpha的范围在0 ~ 255之间, 默认是128)
tag_ripple_durationinteger涟漪效应的持续事件(以毫秒为单位, 默认是1000ms)
tag_enable_crossboolean启用云标签的X图标(点击删除)(默认是false)
tag_cross_widthdimension叉叉的宽度(叉叉的点击区域,默认等于tagview的高度)
tag_cross_colorcolor叉叉的颜色(默认是Color.BLACK)
tag_cross_line_widthdimension叉线的宽度(默认1dp)
tag_cross_area_paddingdimension叉叉的padding值(默认是10dp)
tag_support_letters_rltboolean是否支持“字母显示与RTL(如:Android -> diordna)风格(默认为false)

You can set these attributes in layout file, or use setters(each attribute has get and set method) to set them.

  你可以在你的布局文件中设置这些属性,或者使用set方法来为TagView设置属性。

主题

themecodevaluedescription
noneColorFactory.NONE-1自定义主题时,必须优先设置该参数
randomColorFactory.RANDOM0为每一个标签设置一个随机的颜色
pure_cyanColorFactory.PURE_CYAN1所有的TagView使用纯青色
pure_tealColorFactory.PURE_TEAL2所有的TagView使用纯绿色

标签文本方向

directioncodevaluedescription
ltrView.TEXT_DIRECTION_LTR3由左到右(默认)
rtlView.TEXT_DIRECTION_RTL4由右到左

注:是标签内文本方向

标签文本水平对齐

gravitycodevaluedescription
leftGravity.LEFT3居左(默认)
centerGravity.CENTER17居中
rightGravity.RIGHT5居右

方法

  • 为TagView设置监听事件,有单击事件,长按事件,点击叉叉事件
mTagContainerLayout.setOnTagClickListener(new TagView.OnTagClickListener() {

    @Override
    public void onTagClick(int position, String text) {
        // ...
    }

    @Override
    public void onTagLongClick(final int position, String text) {
        // ...
    }

    @Override
    public void onTagCrossClick(int position) {
        // ...
    }
});
  • 设置标签的最大长度
mTagContainerLayout.setTagMaxLength(int max);
  • Use getTagText(int position) to get TagView text at the specified location.(通过position获取某个标签的文字)
String text = mTagContainerLayout.getTagText(int position);
  • 获取所有标签的文字
List<String> list = mTagContainerLayout.getTags();
  • 如果你把container_enable_drag 属性设置为 true (即设置可拖拽模式), 当你拖拽一个TagView ,你可以使用 getTagViewState()获取当前TagView的状态位。
  • 这里有三个状态位:
  • ViewDragHelper.STATE_IDLE(空闲模式)
  • ViewDragHelper.STATE_DRAGGING(正在拖拽模式)
  • ViewDragHelper.STATE_SETTLING(正在设置模式)
int state = mTagContainerLayout.getTagViewState();
  • 设置主题
  • 如果你想要自定义TagView的主题,首先要设置主题属性值为ColorFactory.NONE,然后再设置其他的主题属性
// Set library provides theme
mTagContainerLayout.setTheme(ColorFactory.PURE_CYAN);
// Set customize theme
mTagContainerLayout.setTheme(ColorFactory.NONE);
mTagContainerLayout.setTagBackgroundColor(Color.TRANSPARENT);
  • 设置文本方向
  • 总共致支持两种方向
    View.TEXT_DIRECTION_LTRView.TEXT_DIRECTION_RTL
mTagContainerLayout.setTagTextDirection(View.TEXT_DIRECTION_RTL);
  • 使用setTagTypeface(Typeface typeface)设置标签的字体样式
Typeface typeface = Typeface.createFromAsset(getAssets(), "iran_sans.ttf");
mTagContainerLayout.setTagTypeface(typeface);

设置完标签的属性之后,可以设置tags或者是添加一个tag

  • 设置标签,参数为 List 或 String[]:setTags()
mTagContainerLayout.setTags(List<String> tags);
  • 追加一个标签
mTagContainerLayout.addTag(String text);
  • 定点(插入位置为定点之前)插入一个标签
mTagContainerLayout.addTag(String text, int position);
  • 删除指定位置的标签
mTagContainerLayout.removeTag(int position);
  • 删除所有标签
mTagContainerLayout.removeAllTags();
  • 为每一个TagView设置颜色
List<int[]> colors = new ArrayList<int[]>();
//int[] color = {TagBackgroundColor, TabBorderColor, TagTextColor}
int[] color1 = {Color.RED, Color.BLACK, Color.WHITE};
int[] color2 = {Color.BLUE, Color.BLACK, Color.WHITE};
colors.add(color1);
colors.add(color2);
mTagcontainerLayout.setTags(tags, colors);

版本迭代日志

1.1.1(2017-4-16)

  • Customize the color of the TagView, see #51
  • Fixed issue #50, #49

1.1.0(2017-3-5)

  • Fixed issue #45
  • Support ‘letters show with RTL(eg: Android -> diordnA)’ style

1.0.6(2017-2-14)

  • Fix bugs

1.0.5(2016-11-9)

  • Add cross view for TagView

1.0.4(2016-10-30)

1.0.3(2016-4-3)

  • Add getTags() method to get the list for all tags
  • Fixed bugs in ListView/RecyclerView

1.0.2(2016-1-18)

  • Support gravity for TagContainerLayout
  • Support set typeface

1.0.1(2016-1-14)

  • Support text direction
  • Add removeAllTags() method for remove all TagViews
  • Fixed issue #1
  • Fixed other bugs

1.0.0(2016-1-6)

  • First release

Sample App

APK

About

If you have any questions, contact me: lujun.byte#gmail.com.

License

Copyright 2015 lujun

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

github地址

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值