ClipDrawable 实现图片渐变现实

clip.xml

<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:clipOrientation="vertical"
android:drawable="@drawable/iii"
android:gravity="top" />

<ImageView
android:id="@+id/data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/clip" />

Java代码

final ClipDrawable draw = (ClipDrawable) imageView.getBackground();

draw.setLevel(draw.getLevel() + 1000);

注意: 默认的Level值是0,表示图片被这个裁剪,故图片是不可见的。当值达到10000是代码裁剪为0,图片可以完全显示。

原文地址:https://www.cnblogs.com/lzh-Linux/p/4974038.html