FlycooLabelView显示角标效果

来源:互联网 发布:成都数据恢复公司 编辑:程序博客网 时间:2024/06/05 04:59

github上的一段开源代码,功能很简单,就是实现角标效果,如下:


原理:

实现了一个LabelView类,继承View类,重写onDraw()、onMeasure()等方法,自定义界面

使用方法:

1、添加依赖 

compile 'com.flyco.labelview:FlycoLabelView_Lib:1.0.2@aar'

2、配置xml例子

<FrameLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"><ImageView    android:layout_width="match_parent"    android:layout_height="200dp"    android:scaleType="centerCrop"    android:src="@mipmap/haha"/>    <com.flyco.labelview.LabelView        xmlns:lv="http://schemas.android.com/apk/res-auto"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="10dp"        android:paddingRight="10dp"        lv:lv_text="Hot"        lv:lv_text_size="12sp"/>    <com.flyco.labelview.LabelView        xmlns:lv="http://schemas.android.com/apk/res-auto"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="right"        lv:lv_background_color="#3F9FE0"        lv:lv_gravity="TOP_RIGHT"        lv:lv_text="二哈"        lv:lv_text_size="12sp"/>    <com.flyco.labelview.LabelView        xmlns:lv="http://schemas.android.com/apk/res-auto"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="bottom|left"        lv:lv_background_color="#F6CE59"        lv:lv_gravity="BOTTOM_LEFT"        lv:lv_text="会员"        lv:lv_text_all_caps="false"        lv:lv_text_size="12sp"/>    <com.flyco.labelview.LabelView        xmlns:lv="http://schemas.android.com/apk/res-auto"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="bottom|right"        lv:lv_background_color="#EC7263"        lv:lv_gravity="BOTTOM_RIGHT"        lv:lv_text="new"/></FrameLayout><FrameLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layout_marginTop="40dp">    <ImageView        android:layout_width="match_parent"        android:layout_height="200dp"        android:scaleType="centerCrop"        android:src="@mipmap/haha"/>    <com.flyco.labelview.LabelView        xmlns:lv="http://schemas.android.com/apk/res-auto"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        lv:lv_fill_triangle="true"        lv:lv_text=""        lv:lv_text_size="12sp"/>    <com.flyco.labelview.LabelView        xmlns:lv="http://schemas.android.com/apk/res-auto"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="right"        android:paddingLeft="5dp"        android:paddingRight="5dp"        lv:lv_background_color="#3F9FE0"        lv:lv_fill_triangle="true"        lv:lv_gravity="TOP_RIGHT"        lv:lv_text="大哈"        lv:lv_text_size="12sp"/>    <com.flyco.labelview.LabelView        xmlns:lv="http://schemas.android.com/apk/res-auto"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="bottom|left"        lv:lv_background_color="#F6CE59"        lv:lv_fill_triangle="true"        lv:lv_gravity="BOTTOM_LEFT"        lv:lv_text="会员"        lv:lv_text_all_caps="false"        lv:lv_text_size="12sp"/>    <com.flyco.labelview.LabelView        xmlns:lv="http://schemas.android.com/apk/res-auto"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="bottom|right"        lv:lv_background_color="#EC7263"        lv:lv_fill_triangle="true"        lv:lv_gravity="BOTTOM_RIGHT"        lv:lv_text="new"/></FrameLayout>
3、具体属性介绍

nameformatdescriptionlv_textstring设置文字内容lv_text_colorcolor设置文字颜色,默认#fffffflv_text_sizedimension设置文字大小,默认11splv_text_boldboolean设置文字是否支持加粗,默认truelv_text_all_capsboolean设置文字是否支持全部大写,默认truelv_background_colorcolor设置背景颜色,默认"#FF4081"lv_min_sizedimension设置LabelView所在矩形最小宽高,默认mFillTriangle?35dp:50dplv_paddingdimension设置文字上下padding,默认3.5dp,mFillTriangle为true时无效lv_gravityenum设置LabelView方向,支持左上或右上或左下或右下,默认左上lv_fill_triangleboolean设置是否填充三角区域,默认false4、github源码地址

https://github.com/H07000223/FlycoLabelView

0 0
原创粉丝点击