• Stars
    star
    571
  • Rank 77,601 (Top 2 %)
  • Language
    Java
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

一个可配置的迷你版轻量级 Label 辅助类,支持多种配置效果。

AvatarLabelView

一个可配置的迷你版轻量级 Label 辅助类,支持多种配置效果,具体不同配置展示效果如下图。

说明文档

如下是关于 Label View 的相关使用方式、属性说明、拓展自定义的解释说明。

使用样例

<cn.label.avatarlabelview.LabelImageView
    app:textContent="晚场"
    app:textContentSize="14sp"
    app:direction="rightTop"
    app:labelTopDistance="20dp"
    app:labelTopPadding="10dp"
    app:labelBottomPadding="10dp"
    app:backgroundColor="@color/colorPrimaryDark"
    android:src="@mipmap/ic_launcher"
    android:background="#f3a212"
    android:layout_width="150dp"
    android:layout_height="100dp"/>

已实现类说明

类别 类名 说明
library LabelViewHelper 标签辅助核心实现类
library LabelView 基于 LabelViewHelper 实现的一个纯标签 View,可嵌套在 ViewGroup 中使用等
demo LabelImageView 基于 LabelViewHelper 实现的一个具备标签的 ImageView,可属性配置等
demo LabelLinearLayout 基于 LabelViewHelper 实现的一个具备标签的 LinearLayout,可属性配置等
customer XxxView 类比上面 demo 中基于 LabelViewHelper 实现自己的 Label View

属性说明

属性 含义
app:backgroundColor Label 的背景颜色
app:textTitleColor 第一行文字的颜色,如果 Label 作为单行(不设置textTitle)则无效
app:textContentColor 第二行文字的颜色
app:textTitle 第一行文字的内容,如果文字过长注意调节 labelTopPadding 的值变大,单行 Label 时不要设置此值
app:textContent 第二行文字的内容,单行显示时推荐用此
app:textTitleSize 第一行文字的大小,默认10sp,如果 Label 作为单行(不设置textTitle)则无效
app:textContentSize 第二行文字的大小,默认12sp
app:labelTopPadding 第一行文字上边缘距离背景顶部(注意三角形或者梯形)的偏移量,默认为15dp
app:labelCenterPadding 第一行文字底部与第二行文字顶部之间的偏移距离
app:labelBottomPadding textContent 文字与 Label 背景底部的空隙距离,默认为 10dp
app:labelTopDistance 当设置该值大于0时显示的 Label 为梯形的样式,梯形上顶宽度与该值成正比;当不设置时 Label 为三角形样式
app:textTitleStyle 第一行文字的样式,normal、italic、bold,如果 Label 作为单行(不设置textTitle)则无效
app:textContentStyle 第二行文字的样式,normal、italic、bold
app:direction Label 的位置,leftTop 或者 rightTop

拓展为自己 View 使用方式

  1. 在自己的自定义 View 构造方法创建 LabelViewHelper 对象。
  2. 在自己的自定义 View 相关绘制方法(onDraw、dispatchDraw 等)中调用 LabelViewHelper 的 drawLabel 方法。
  3. 至此你的自定义 View 就支持可配置的 Label 效果了,如需别的拓展可以参考 demo 或者查看 LabelViewHelper 其他方法。

具体拓展应用到自己自定义的其他控件中如下:

public class LabelImageView extends YourCustomerView {
    //......
    public LabelImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mLabelViewHelper = new LabelViewHelper(context, attrs);
    }

    //注意:ViewGroup 最好重写 dispatchDraw 方法
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mLabelViewHelper.drawLabel(this, canvas);
    }
    //......
}

License 声明

MIT License

Copyright (c) 2016 yanbo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

RNPolymerPo

一个基于 React Native 的 Android 企业级应用。
JavaScript
598
star
2

Android-Blog-Source

Blog Demo Storage
Java
587
star
3

MagicFloatView

一个可配置及自定义拓展漂浮路径的迷你版轻量级 MagicFlyLinearLayout 漂浮控件。
Java
294
star
4

SlideLayout

一个超级迷你轻量级全方向完美侧滑控件,兼容各种嵌套与被嵌套滑动控件。
Java
269
star
5

android-build-filter-gradle-plugin

一个小众需求下移除 Android 构建中 Jar 包、AAR 包、构建冗余 class 文件的 Gradle 插件。
Groovy
168
star
6

SmallReptileTraining

Python reptile skill training.
Python
111
star
7

DreamDrawable

一个项目玩转 Android 自定义 Drawable。
Java
68
star
8

app-tiny-R-gradle-plugin

一个有效优化 apk 应用 Field 个数、包大小的构建(Hook)工具。
Groovy
57
star
9

android-tracepath

一个基于 iputils/tracepath6.c 移植定制的 Android 普通权限应用程序通过网络追踪并显示报文到达目的主机所经过的路由信息。
C
27
star
10

android-crash

一个 Android 平台支持捕获 Native(C/C++) 层和 Java 层崩溃异常的迷你库。
C++
24
star
11

mtc-kcp

一个基于 Kotlin Compiler Plugin 实现的迷你方法耗时无侵入编译插件。
Kotlin
22
star
12

android-7zip

一个使用 C 语言 Native 实现的 android 7zip 压缩解压迷你库.
C
16
star
13

android-hippo

一个基于依赖注解的 Android 核心 case 方法优雅写法库,全面支持 apt、kapt、ksp。
Java
10
star
14

gradle-javadoc-checker

一个检查 android、androidLibrary、java、javaLibrary 代码源文件 javadoc @author 的插件。
Groovy
7
star
15

TsStreamParser

一个 MPEG2-TS 格式流媒体文件的局部表解析项目。
C
6
star
16

AndroidPythonTools

Android develop python tools.
Python
4
star
17

study-http-server-rust

基于学习 Rust 实现最基本 HTTP 1.1 协议功能的 Http Server,代码量很少且非常适合 Rust 语言学习时用来实践。
Rust
4
star
18

game_snake_mini_with_typescript

一个基于纯 TypeScript 的迷你 web 版贪吃蛇小游戏。
TypeScript
2
star