FlycooLabelView显示角标效果

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、具体属性介绍

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

https://github.com/H07000223/FlycoLabelView

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值