Android XML drawable透明渐变不透明

标签 android android-drawable

我想像 Play Music 一样创建一个透明渐变。

drawable/shadow_up.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="90"
        android:startColor="#FF00FF00"
        android:endColor="#00FFFFFF"/>
</shape>

layout/main_layout.xml:

 <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical">

                   <View
                        android:layout_width="match_parent"
                        android:layout_height="25dp"
                        android:background="@drawable/shadow_up"/>
</LinearLayout>

但是渐变不是透明的。如何解决这个问题?

enter image description here

Play Music 的渐变:

enter image description here

它是透明的。

最佳答案

最可能的答案是你的渐变 View 不与 ListView 重叠 - 换句话说, ListView 在你的渐变之上,渐变 xml 是正确的,它的 View 定位错误。你应该尝试更像这样的东西

<ReltaiveLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  Your litview goes here, with both dimensions match parent

                 <View
                    android:layout_alignParentBottom="true"
                    android:layout_width="match_parent"
                    android:layout_height="25dp"
                    android:background="@drawable/shadow_up"/>
</RelativeLayout>

关于Android XML drawable透明渐变不透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29669440/

相关文章:

android - diffutil排序数组适配器位置

android - 为什么 sharedpreferences 的 getStringSet 方法不起作用?

android - 从可绘制资源中更改 png 图标颜色

android - 在 Android 中制作自定义可绘制形状

android - 在 Android Studio 的 Gradle 中创建 Product Flavor 时,主模块是如何使用的?

android - 当焦点在 XML 中丢失时隐藏布局

java - 使用单选按钮创建测试/问卷 - Android

当我尝试创建可绘制资源文件时,Android Studio 出现奇怪的错误

java - Android 比较背景颜色和颜色

java - 如何在 Android Studio 中使用 TextView 的矩形背景?