Coder Social home page Coder Social logo

knowfly / labellayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lcodecorex/labellayout

0.0 2.0 0.0 907 KB

A light but strong tags-selecter Android library. 标签(label/tag)展示/选择控件,使用简单,个性化方便。

Java 100.00%

labellayout's Introduction

最简洁的标签(label/tag)选择/展示控件----LabelLayout

LabelLayout只是用于标签布局(layout),搭配CheckBox使用,标签样式可以随意更换,完全没有束缚,小而精悍。(支持API 9 及以上)

Demo图

属性

  • label_horizontalSpacing 水平方向上标签之间的距离
  • label_verticalSpacing 竖直方向上标签之间的距离
  • label_checkboxLayout 传入CheckBox布局(也就是标签的样式)
  • label_enableDivider 是否需要在标签行间加分割线,默认为false
  • label_dividerHeight 行间分割线的高度
  • label_dividerColor 行间分割线的颜色

使用

添加gradle依赖

compile 'com.lcodecorex:labellayout:1.0.1'

方法及回调

  1. 定义标签数据Bean实现ILabel接口
public interface ILabel {
    //warning! Ids should be unique!!!
    public String getId();
    public String getName();
}

注意getId()放回的id值必须是独特的,不可重复。

  1. layout布局
<com.lcodecorex.LabelLayout
    android:id="@+id/label_me"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    app:label_horizontalPadding="16dp"
    app:label_horizontalSpacing="16dp"
    app:label_verticalPadding="16dp"
    app:label_verticalSpacing="32dp"
    app:enableDivider="true" />
  1. 设置标签,使用setLabels()方法
labelLayout.setLabels(List<ILabel> labels);
  1. 添加标签选择监听器
label_me.setOnCheckChangedListener(new LabelLayout.OnCheckListener() {
            @Override
            public void onCheckChanged(ILabel label,boolean isChecked) {}
            
             @Override
             public void onBeyondMaxCheckCount() {
             
             }
        });
  1. 如果是需要选择标签,可以调用setMaxCheckCount(int)方法,选中的标签超过这个数checkListener的onBeyondMaxCheckCount()方法会被回调。

  2. 其它方法

  • getCheckedLabelsCount 获取当前被选中的标签数量
  • getCheckedLabelIds() 获取被选中的标签的id列表
  • getCheckedIdsAsJson() 获取json序列化之后的id的json串

个性化(可参考默认样式:view_label_common.xml)

--- 主布局

<com.lcodecorex.LabelLayout
    android:id="@+id/label_all"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    app:label_horizontalPadding="16dp"
    app:label_horizontalSpacing="16dp"
    app:label_verticalPadding="16dp"
    app:label_verticalSpacing="32dp"
    app:checkboxLayout="@layout/checkbox_gray"
    app:enableDivider="true" />

--- checkbox_gray.xml

<?xml version="1.0" encoding="utf-8"?>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="32dp"
    android:layout_margin="10dp"
    android:background="@drawable/label_selector_gray"
    android:button="@null"
    android:paddingBottom="4dp"
    android:paddingLeft="13dp"
    android:paddingRight="13dp"
    android:paddingTop="4dp"
    android:textColor="#999"
    android:textSize="16sp" />

--- 图一中用的CheckBox样式

<?xml version="1.0" encoding="utf-8"?><!--推荐列表用到的标签显示checkbox-->
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="32dp"
    android:background="@null"
    android:button="@null"
    android:paddingRight="4dp"
    android:textColor="@color/colorPrimary"
    android:textSize="12sp" />

ps Contact me:[email protected]

labellayout's People

Contributors

lcodecorex avatar

Watchers

James Cloos avatar KnowFly avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.