学习自
https://blog.csdn.net/ly1414725328/article/details/50034747
看见开源中国一个很有意思的功能
思路
通过一个渐变的view去覆盖这些字。
最正确思路
web端实现。我简单分析了下,开源中国这里用的肯定是H5和Java代码互调,所以这部分功能肯定是由web前端实现的
不过我们还是讲一下安卓的实现
渐变
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:angle="90" android:endColor="#11ffffff" android:startColor="#f0ffffff" android:type="linear" /> </shape>布局
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/colorAccent" android:text="我是自定义Dialog" android:textSize="30sp" /> <View android:layout_width="235dp" android:layout_height="40dp" android:background="@drawable/text_gradient" /> </FrameLayout>效果
啥时候Android会用到这个功能
1.没有web端替你实现的时候
2.你想做性能优化的时候。因为这是一个性能优化很好的点,你不必加载所有的数据,因为用户不一定感兴趣这块内容。所以你可以减少网络传输量(当然顺带一点电量消耗),也可以减少内存占用。(当然也顺带一点UI消耗)
