Android三角标签View:TriangleLabelView
在一些商城、产品推销类APP中,如淘宝、京东、电影门票销售、商品降价促销这类的APP,常常会在其APP中看到,某些商品的左上角或者右上角有一些三角的标签,这些标签View的实现很多种,我在以前介绍过一种第三方开源的实现,见附录文章1。
本文再介绍一种类似实现:TriangleLabelView。
TriangleLabelView是第三方开源项目,其在github上的项目主页是:https://github.com/shts/TriangleLabelView
实现结果如图所示:
TriangleLabelView可以通过配置xml文件即可实现,我写一个例子说明:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="zhangphil.demo.MainActivity">
-
- <RelativeLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true">
-
- <TextView
- android:layout_width="200dip"
- android:layout_height="100dip"
- android:layout_centerInParent="true"
- android:background="@android:color/holo_blue_light"
- android:gravity="center"
- android:text="Zhang Phil" />
-
- <jp.shts.android.library.TriangleLabelView xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- app:backgroundColor="@android:color/holo_orange_light"
- app:corner="leftTop"
- app:labelBottomPadding="5dp"
- app:labelCenterPadding="0dp"
- app:labelTopPadding="10dp"
- app:primaryText="CSDN"
- app:primaryTextColor="@android:color/holo_red_light"
- app:primaryTextSize="16sp"
- app:secondaryText="blog"
- app:secondaryTextColor="@android:color/holo_purple"
- app:secondaryTextSize="11sp" />
-
- </RelativeLayout>
-
- </RelativeLayout>
代码运行结果如图: