如何在 Android 中添加完全透明的 semi-transparent 渐变

How to add a fully transparent to semi-transparent gradient in Android

我有一种情况想添加一个图像视图来实现与此应用相同的效果

如您所见,视图底部隐藏了一个可绘制对象或其他东西,添加了透明渐变。我怎样才能达到同样的效果?

将这个可绘制对象放在布局的底部:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#FFFFFF"
        android:endColor="@android:color/transparent"
        android:angle="90" />
</shape>

您的布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    android:background="@android:color/white" > 
    <View
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:background="@drawable/gradient"
        android:layout_gravity="bottom"/>

</FrameLayout>

好吧,您可以在 xml 中使用 listView 的 fadingEdge 属性。制作一个列表视图,然后添加项目 xml(特别是图像,如您上面提到的)。

android:fadingEdge="horizontal" android:fadingEdgeLength="30dp" android:fillViewport="false" android:requiresFadingEdge="vertical"

我认为您可以更改该图像视图的 alpha 值。经过 this and this了解更多详情。