Android 添加标签;角标;控件角落添加Tip

使用LabelView
是在github上一个开源的标签库。其项目主页是:https://github.com/linger1216//labelview 

 

在Androidstudio里面使用:

在项目级别的build.gradle:

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

在app的build.gradle:

dependencies {
	compile 'com.github.linger1216:labelview:v1.1.2'
}

提供带标签的控件:

(这几个的属性label_text,设置的文字因为在studio预览都没有显示出来,程序启动后都会显示出来)

对应的LabelButtonView:带角标的Button;

对应的LabelImageView:带角标的ImageView;

对应的LabelTextView:带角标的TextView;

上面效果的几个代码是:

LabelButtonView:

<com.lid.lib.LabelButtonView
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toSartOf="@id/image"
    app:layout_constraintBottom_toBottomOf="parent"
    android:id="@+id/button"
    android:layout_width="150dp"
    android:layout_height="48dp"
    android:background="#03a9f4"
    android:gravity="center"
    android:text="我是按钮"
    android:textColor="#ffffff"
    app:label_backgroundColor="#C2185B"
    app:label_distance="20dp"
    app:label_height="20dp"
    app:label_orientation="RIGHT_TOP"
    app:label_text="哈哈"
    app:label_textColor="#FFFFFF"
    app:label_textSize="12sp"
    />

LabelImageView:

<com.lid.lib.LabelImageView
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:id="@+id/image"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:scaleType="centerCrop"
    android:src="@mipmap/ic_launcher_round"
    android:background="#03a9f4"
    app:label_backgroundColor="#C2185B"
    app:label_orientation="LEFT_TOP"
    app:label_distance="30dp"
    app:label_height="30dp"
    app:label_textColor="#FFFFFF"
    app:label_text="嘿嘿" />

LabelTextView:

<com.lid.lib.LabelTextView
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:padding="16dp"
    android:text="TextView"
    android:textColor="#ffffff"
    app:label_backgroundColor="#C2185B"
    app:label_distance="15dp"
    app:label_orientation="LEFT_TOP"
    app:label_text="嗯嗯"
    app:label_textSize="10sp" />

其中

label_backgroundColor:是标签的背景色,
label_height:标签的高度,也可以说是标签的厚度。。。
label_orientation:标签的位置,分为左上、左下、右上、右下。分别对应:LEFT_TOP,LEFT_BOTTOM,RIGHT_TOP,RIGHT_BOTTOM
label_text:标签的显示文字
label_textColor:标签文字的颜色
label_textSize:标签文字的大小
label_distance:是标签的距离:为0时也就是被label背景色全覆盖,不留白

 

也可以把某个LabelButtonView、LabelImageView、LabelTextView当成单独的控件使用,我是这么使用的:

我的RecycleView的item布局需要打标签,所以:

<com.lid.lib.LabelTextView
        android:layout_alignParentRight="true"
        android:id="@+id/item_overdue_tip"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:padding="0dp"
        android:text=""
        android:textColor="#ffffff"
        app:label_backgroundColor="#03A9F4"
        app:label_distance="13dp"
        app:label_orientation="RIGHT_TOP"
        app:label_text="Tip"
        app:label_textColor ="#FFFFFF"
        app:label_textSize="10sp" />

也是正常使用,调整好相对于父控件的位置就好~

 

 

End---------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值