Android实现图片一边的三角形边框效果

Android实现图片一边的三角形边框效果,第1张

概述Android实现图片一边的三角形边框效果 在每一个图片的某一侧都可以展示出一个三角形的边框视图,就是咱们的三角形标签视图.这个视图在电商类APP当中比较常用,使用过ebay的同学应该都还记得有些商品的左上角或者右上角都会显示一个三角形的边框,用于给人一个直观的商品正在促销,或者刚刚上线的直观感受.我们可以看看实现后的效果如下: 在真实的APP当中,我们还会加上一个SrcollView控件,这样子才可以进行不断地上下浏览.我们这里主要是为了让大家明白这个视图是该如何实现的,就不演示SrcollView控件下的做法了,直接在线性布局下做一个

在每一个图片的某一侧都可以展示出一个三角形的边框视图,就是咱们的三角形标签视图。这个视图在电商类APP当中比较常用,使用过ebay的同学应该都还记得有些商品的左上角或者右上角都会显示一个三角形的边框,用于给人一个直观的商品正在促销,或者刚刚上线的直观感受。我们可以看看实现后的效果如下:


在真实的APP当中,我们还会加上一个SrcollVIEw控件,这样子才可以进行不断地上下浏览。我们这里主要是为了让大家明白这个视图是该如何实现的,就不演示SrcollVIEw控件下的做法了,直接在线性布局下做一个简单的说明。由于在线性布局上面一共具有四张图,因此咱们可以先单独编写每一个imagevIEw的自定义view,然后<include>的语法将他们组合起来,这样可以提高UI开发的效率,进行协同工作与开发。首先咱们先实现左上角和右上角的triangle vIEw.

在build.gradle文件当中相应地方添加如下代码,导入相应的maven库:

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

之后在另一个build.gradle文件当中添加库:

dependencIEs {      implementation 'com.github.shts:TriangleLabelVIEw:1.1.2'  }

咱们的前期工作就这样做好啦,现在就开始正式编写咱们的每一个三角形边框视图啦,首先是第一个位于左上角的视图

一.card_left_top.xml:

<?xml version="1.0" enCoding="utf-8"?><androID.support.v7.Widget.CardVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"  xmlns:app="http://schemas.androID.com/apk/res-auto"  androID:layout_wIDth="match_parent"  androID:layout_height="match_parent">  <relativeLayout    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent">    <ImageVIEw      androID:ID="@+ID/image"      androID:scaleType="centerCrop"      androID:src="@drawable/s_image_2"      androID:layout_wIDth="match_parent"      androID:layout_height="match_parent" />    <jp.shts.androID.library.TriangleLabelVIEw      androID:layout_wIDth="match_parent"      androID:layout_height="match_parent"      androID:layout_alignParentleft="true"      androID:layout_alignParenttop="true"      app:backgroundcolor="@color/yellow_900"      app:corner="lefttop"      app:labelBottompadding="5dp"      app:labelCenterpadding="0dp"      app:labeltoppadding="10dp"      app:primaryText="New"      app:primaryTextcolor="@color/yellow_500"      app:primaryTextSize="16sp"      app:secondaryText="01"      app:secondaryTextcolor="@color/yellow_100"      app:secondaryTextSize="11sp" />  </relativeLayout></androID.support.v7.Widget.CardVIEw>

编写好后在prevIEw当中显示如下:


下面是位于右上角的视图

二.card_right_top.xml:

<?xml version="1.0" enCoding="utf-8"?><androID.support.v7.Widget.CardVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"  xmlns:app="http://schemas.androID.com/apk/res-auto"  androID:layout_wIDth="match_parent"  androID:layout_height="match_parent">  <relativeLayout    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent">    <ImageVIEw      androID:ID="@+ID/image"      androID:scaleType="centerCrop"      androID:src="@drawable/s_image_4"      androID:layout_wIDth="match_parent"      androID:layout_height="match_parent" />    <jp.shts.androID.library.TriangleLabelVIEw      androID:layout_wIDth="match_parent"      androID:layout_height="match_parent"      androID:layout_alignParentRight="true"      androID:layout_alignParenttop="true"      app:backgroundcolor="@color/teal_900"      app:corner="righttop"      app:labelBottompadding="5dp"      app:labelCenterpadding="0dp"      app:labeltoppadding="10dp"      app:primaryText="New"      app:primaryTextcolor="@color/teal_500"      app:primaryTextSize="16sp"      app:secondaryText="01"      app:secondaryTextcolor="@color/teal_100"      app:secondaryTextSize="11sp" />  </relativeLayout></androID.support.v7.Widget.CardVIEw>

三.card_right_buttom.xml:

<?xml version="1.0" enCoding="utf-8"?><androID.support.v7.Widget.CardVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"  xmlns:app="http://schemas.androID.com/apk/res-auto"  androID:layout_wIDth="match_parent"  androID:layout_height="match_parent">  <relativeLayout    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent">    <ImageVIEw      androID:ID="@+ID/image"      androID:scaleType="centerCrop"      androID:src="@drawable/s_image_3"      androID:layout_wIDth="match_parent"      androID:layout_height="match_parent" />    <jp.shts.androID.library.TriangleLabelVIEw      androID:layout_wIDth="match_parent"      androID:layout_height="match_parent"      androID:layout_alignParentRight="true"      androID:layout_alignParentBottom="true"      app:backgroundcolor="@color/pink_900"      app:corner="rightBottom"      app:labeltoppadding="10dp"      app:labelCenterpadding="5dp"      app:labelBottompadding="0dp"      app:primaryText="New"      app:primaryTextcolor="@color/pink_500"      app:primaryTextSize="16sp"      app:secondaryText="01"      app:secondaryTextcolor="@color/pink_100"      app:secondaryTextSize="11sp" />  </relativeLayout></androID.support.v7.Widget.CardVIEw>

四.card_left_buttom.xml:

<?xml version="1.0" enCoding="utf-8"?><androID.support.v7.Widget.CardVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"  xmlns:app="http://schemas.androID.com/apk/res-auto"  androID:layout_wIDth="match_parent"  androID:layout_height="match_parent">  <relativeLayout    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent">    <ImageVIEw      androID:ID="@+ID/image"      androID:src="@drawable/s_image_1"      androID:scaleType="centerCrop"      androID:layout_wIDth="match_parent"      androID:layout_height="match_parent" />    <jp.shts.androID.library.TriangleLabelVIEw      androID:layout_wIDth="match_parent"      androID:layout_height="match_parent"      androID:layout_alignParentleft="true"      androID:layout_alignParentBottom="true"      app:backgroundcolor="@color/blue_900"      app:corner="leftBottom"      app:labeltoppadding="10dp"      app:labelCenterpadding="5dp"      app:labelBottompadding="0dp"      app:primaryText="New"      app:primaryTextcolor="@color/blue_500"      app:primaryTextSize="16sp"      app:secondaryText="01"      app:secondaryTextcolor="@color/blue_100"      app:secondaryTextSize="11sp" />  </relativeLayout>

最后咱们整合一下就OK啦!整合后的主活动的代码为:

五.activity_main.xml:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"  xmlns:tools="http://schemas.androID.com/tools"  xmlns:app="http://schemas.androID.com/apk/res-auto"  androID:layout_wIDth="match_parent"  androID:layout_height="match_parent"  androID:orIEntation="vertical"  tools:context=".Fragment2"> <linearLayout    androID:layout_wIDth="match_parent"    androID:layout_height="0dp"    androID:layout_weight="1"    androID:orIEntation="horizontal">    <include androID:layout_wIDth="0dp"      androID:layout_height="match_parent"      androID:layout_weight="1"      androID:layout_margin="2dp"      androID:ID="@+ID/left_top" layout="@layout/card_left_top" />    <include androID:layout_wIDth="0dp"      androID:layout_height="match_parent"      androID:layout_weight="1"      androID:layout_margin="2dp"      androID:ID="@+ID/right_top" layout="@layout/card_right_top" />  </linearLayout>  <linearLayout    androID:layout_wIDth="match_parent"    androID:layout_height="0dp"    androID:layout_weight="1"    androID:orIEntation="horizontal">    <include androID:layout_wIDth="0dp"      androID:layout_height="match_parent"      androID:layout_weight="1"      androID:layout_margin="2dp"      androID:ID="@+ID/left_bottom" layout="@layout/card_left_bottom" />    <include androID:layout_wIDth="0dp"      androID:layout_height="match_parent"      androID:layout_weight="1"      androID:layout_margin="2dp"      androID:ID="@+ID/right_bottom" layout="@layout/card_right_bottom" />  </linearLayout></linearLayout>

完事儿!github源码可以在https://github.com/shts/TriangleLabelView处进行阅读!!!

帅照:


总结

以上所述是小编给大家介绍的AndroID实现图片一边的三角形边框效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

总结

以上是内存溢出为你收集整理的Android实现图片一边的三角形边框效果全部内容,希望文章能够帮你解决Android实现图片一边的三角形边框效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1144259.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存