【Android】边框旁的文字实现模糊效果

【问题】

如何实现几行文字的最上面1行和最下面1行的文字为渐变模糊的效果;

【效果图】


【思路】

简单来说:用一个渐变的透明的View来覆盖两边的文字区域;
具体来说:(这里只考虑[区域2])最外面使用 RelativeLayout,里面的文字内容使用 ListView,上面和下面的模糊效果,使用背景为渐变的 View,(这个View没有任何内容,只是用来覆盖里面的文字)。

【代码】

设置两个颜色用在后面的渐变中

 
 
<color name="rryt_bg_vc_scanning_color_1">#f0ffffff</color>
<color name="rryt_bg_vc_scanning_color_2">#11ffffff</color>

顶部的渐变(res/drawable/rlyt_bg_vc_scanning_device_top.xml)

 
 
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:endColor="@color/bg_color_1"
android:startColor="@color/bg_color_2"
android:type="linear" />
</shape>

底部的渐变(res/drawable/rlyt_bg_vc_scanning_device_bottom.xml)

 
 
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:endColor="@color/bg_color_2"
android:startColor="@color/bg_color_1"
android:type="linear" />
</shape>

布局里面实现

 
 
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
 
<ListView
android:id="@+id/lv_vc_scanning_device"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
 
<View
android:layout_width="match_parent"
android:layout_height="32dp"
android:background="@drawable/rlyt_bg_vc_scanning_device_top"
android:layout_alignParentTop="true"/>
 
<View
android:layout_width="match_parent"
android:layout_height="32dp"
android:background="@drawable/rlyt_bg_vc_scanning_device_bottom"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值