AndroidTagView 云标签
来源:互联网 发布:淘宝上给差评有用么 编辑:程序博客网 时间:2024/05/22 16:49
AndroidTagView云标签
这是一个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了。下文会展示更多有用的自定义属性:
属性
You can set these attributes in layout file, or use setters(each attribute has get and set method) to set them.
你可以在你的布局文件中设置这些属性,或者使用set方法来为TagView设置属性。
主题
标签文本方向
注:是标签内文本方向
标签文本水平对齐
方法
- 为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 thememTagContainerLayout.setTheme(ColorFactory.PURE_CYAN);
// Set customize thememTagContainerLayout.setTheme(ColorFactory.NONE);mTagContainerLayout.setTagBackgroundColor(Color.TRANSPARENT);
- 设置文本方向
- 总共致支持两种方向
View.TEXT_DIRECTION_LTR
和View.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)
- Support ripple effect(Call requires API level 11), like Android CustomButton
- Fix bugs
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 lujunLicensed 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.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.
github地址
0 0
- AndroidTagView 云标签
- AndroidTagView 云标签
- 自定义控件—AndroidTagView标签,可在标签中添加图片,控制图片的位置
- 标签云
- 标签云
- 标签云
- 标签云
- 标记标签云
- 新云标签使用说明
- 新云标签
- OpenGL标签云
- WordPress 彩色标签云
- 纯js标签云
- tagcloud标签云
- 搜索 云标签实现
- Drupal7_8: 标签云
- 生成标签云
- 3d标签云
- 【搜索】洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace
- bzoj4527: K-D-Sequence
- Stories 6-8
- python基础学习(一):字符串
- 持续集成之Jenkins+Gitlab简介
- AndroidTagView 云标签
- 逆向工程核心原理学习笔记(十八):栈帧5:设置add()函数的局部变量(x,y)
- Android内存抖动及内存泄漏的发现、定位和解决
- 解决本地tensorboard找不到命令的问题
- 递归实现汉诺塔
- CSS3实现图片抽屉式效果
- win10与ubuntu双系统启动问题
- Hibernate 配置文件或映射文件没有提示问题
- Android设计模式(1)