使用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" />
也是正常使用,调整好相对于父控件的位置就好~