如何在Android中添加完全透明到半透明的渐变

时间:2019-09-01 10:54:52

标签: android android-imageview android-drawable

我遇到一种情况,想添加与该应用程序具有相同效果的图像视图

Screenshot

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

3 个答案:

答案 0 :(得分:1)

将此可绘制对象放置在布局的底部:

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

答案 1 :(得分:0)

那么,您可以在xml中使用listView的fadingEdge属性。创建一个listView,然后添加项目xml(尤其是如上所述的图像)。

android:fadingEdge="horizontal" android:fadingEdgeLength="30dp" android:fillViewport="false" android:requiresFadingEdge="vertical"

答案 2 :(得分:0)

我认为您可以更改该图像视图的Alpha值。经过 thisthis了解更多详情。

相关问题