首页 > 解决方案 > 如何在Android中添加完全透明到半透明的渐变

问题描述

我有一种情况,我想添加一个图像视图,效果与此应用程序相同

截屏

正如您所注意到的,有一个可绘制或隐藏视图底部的东西添加了透明渐变。我怎样才能达到同样的效果?

标签: androidandroid-imageviewandroid-drawable

解决方案


将此drawable放在布局的底部:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#FFFFFF"
        android:endColor="@android:color/transparent"
        android:angle="90" />
</shape>

你的布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white" > 
    <View
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:background="@drawable/gradient"
        android:layout_gravity="bottom"/>

</FrameLayout>

推荐阅读