如何使ImageView生效

问题描述 投票:1回答:1

期望:

Screenshot of image with black fade to top

我希望像ImageView顶部的黑色阴影一样,只在顶部。我试过为这样的ImageView背景创建一个形状:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/black_1_50"/>
            <!--shadow Color-->
        </shape>
    </item>

    <item
            android:left="0dp"
            android:right="0dp"
            android:top="20dp"
            android:bottom="0dp">
        <shape android:shape="oval">
            <solid android:color="@color/white_1_60"/>
        </shape>
    </item>
</layer-list>

但它不起作用。有解决方案吗

android xml android-layout imageview
1个回答
0
投票

您的活动或片段的布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/ic_launcher_background"
        android:adjustViewBounds="true" />

<View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/shadoweffects" />
 </FrameLayout>

drawable shadoweffects.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">

<gradient
        android:angle="90"
        android:endColor="#aa000000"    
        android:startColor="#00ffffff"
        android:centerColor="#00ffffff" />
</shape>

根据需求变化颜色

© www.soinside.com 2019 - 2024. All rights reserved.