代码之家  ›  专栏  ›  技术社区  ›  Alaa AbuZarifa

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

  •  0
  • Alaa AbuZarifa  · 技术社区  · 7 年前

    我想在按钮背景上实现精确的效果, 但还没有成功!有什么帮助吗?

    这是图片

    enter image description here


    到目前为止我的尝试 (渐变\u 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>
    

    …结果不多了!

    enter image description here

    布局

           <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>
    
    2 回复  |  直到 7 年前
        1
  •  1
  •   tj2611    7 年前

    尝试以下代码可以帮助您解决问题

    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:endColor="#ffffff"
        android:centerColor="#90ffffff"
        android:startColor="#65ffffff"
        android:angle="-90"/>
    </shape>
    
        2
  •  0
  •   Prakash S    7 年前

    使用下面的文本视图和使用相对布局或其他布局的文本视图下面的对齐按钮

       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" />