【问题标题】:How to make a transparent white gradient background如何制作透明的白色渐变背景
【发布时间】:2018-12-02 14:15:14
【问题描述】:

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

这是图片


我目前的尝试(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>

【问题讨论】:

  • 布局是什么?
  • @TheWanderer 现在检查..
  • TextView 和 FrameLayout 需要在另一个 FrameLayout 中。将 TextView 的底部边距设置为 60dp(高度 + 按钮底部边距)。

标签: android xml android-layout gradient android-drawable


【解决方案1】:

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

<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】:

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

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

属性会为 textview 创建淡入淡出的边缘效果。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-26
    • 2011-03-05
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多