Android 逐渐变为透明的渐变背景

Android Gradient Background that fades in to being Transparent

我正在尝试让一个栏淡入到我的 RelativeLayout 的背景中。基本上从后面开始,然后逐渐变为透明。你明白了。

这是我现在的xml:

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

我将其应用到的视图:

 <View
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:background="@drawable/gradient_top" />

问题:视图底部有一个尖锐的结束边缘。我很困惑,因为渐变以透明结束。但是,我仍然在视图底部看到了鲨鱼边缘。我怎样才能调整它以获得衰减边缘?

你的两种颜色都不透明。

@color/black_translucent表示是半透明的,不是透明的

您可以改用 @android:color/transparent