android - 渐变透明背景

标签 android background gradient

我想在图像上获得透明渐变,为什么透明会起作用:

    <android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.twick.screens.custom.SquaredImageView
        android:id="@+id/rv_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/office"/>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#80abcdef" > //TRANSPARENT WORK
    </FrameLayout>

</android.support.v7.widget.CardView>

所以没有

android:background="@drawable/background_gradient_blue_indigo>//TRANSPARENT NOT WORK

背景渐变蓝色靛蓝:

<?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
<gradient
    android:angle="0"
    android:endColor="#800055FA" //80 transaprent
    android:startColor="#807942DF" //80 transparent/>
</shape>

最佳答案

android:alpha=0.8(或任何你想要的浮点值)连同 android:background="@drawable/background_gradient_blue_indigo" 添加到 FrameLayout

但是,请注意,这将使整个 View 透明,而不是背景中的可绘制对象。

关于android - 渐变透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52514816/

相关文章:

android - 在运行时下载网页内容并在 Android webview 上加载

ios - 如何处理后台ios调用中断

html - CSS:背景尺寸:覆盖率50%-可以吗?

java - 为什么这个 RadialGradientPaint 绘制不正确?

android - 如何在 android 中编写异步内容提供程序

java - 在Android上使用GSON解析JSON数据

android - Android WebView 上具有自签名证书的服务 worker

IOS 7 按钮背景不起作用

带渐变的 CSS 三 Angular 形

android层列表不会同时显示渐变和实体