如何制作透明的白色渐变背景

How to make a transparent white gradient background

我想在按钮背景上完成准确的效果, 但还没有成功..!有帮助吗?

这是图片


我目前的尝试(gradient_bg.xml)

 <?xml version="1.0" encoding="utf-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <gradient
        android:angle="90"
        android:endColor="@android:color/transparent"
        android:startColor="#e3ffffff" />

</shape>

..结果没那么多..!

布局

       <TextView
            fontPath="fonts/Roboto-Regular.ttf"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:layout_marginBottom="-20dp"
            android:gravity="start"
            android:text="@string/dummy_big"
            android:textColor="@color/gray_dark"
            android:textSize="13sp"
            tools:ignore="MissingPrefix" />

          <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/gradient_bg">

                <Button
                    fontPath="fonts/Roboto-Bold.ttf"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:layout_gravity="center"
                    android:layout_marginStart="120dp"
                    android:layout_marginTop="20dp"
                    android:layout_marginEnd="120dp"
                    android:layout_marginBottom="20dp"
                    android:background="@drawable/round_solid_primary"
                    android:clickable="true"
                    android:foreground="?selectableItemBackground"
                    android:gravity="center_vertical|center_horizontal"
                    android:text="@string/view_more"
                    android:textColor="@color/ef_white"
                    android:textSize="15sp"
                    tools:ignore="MissingPrefix" />

            </FrameLayout>

使用文本视图下方,并使用相对布局或其他布局将按钮对齐到文本视图下方

   android:requiresFadingEdge="horizontal"
   android:fadingEdgeLength="30dp"

属性将为文本视图创建淡化边缘效果。

   <TextView
        fontPath="fonts/Roboto-Regular.ttf"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:layout_marginBottom="-20dp"
        android:gravity="start"
        android:text="@string/dummy_big"
        android:textColor="@color/gray_dark"
        android:textSize="13sp"
        android:requiresFadingEdge="verticle"
        android:fadingEdgeLength="0dp"
        tools:ignore="MissingPrefix" />

尝试下面的代码可能会帮助您解决问题

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
    android:endColor="#ffffff"
    android:centerColor="#90ffffff"
    android:startColor="#65ffffff"
    android:angle="-90"/>
</shape>