在图像底部添加阴影

时间:2015-08-12 08:25:05

标签: android imageview shadow

如何在图像上添加阴影(右下角)以使标题清晰可见。 见下图。

Image

3 个答案:

答案 0 :(得分:21)

我写了一个具有相同效果的应用程序。我做的是,我创建了一个 FrameLayout ,其中包含 ImageView ,另一个 View 具有与ImageView相同的高度。然后我在查看

中添加透明渐变背景

示例:

布局文件:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

    <View
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:background="@drawable/gradient" />

</FrameLayout>

<强>抽拉/ gradient.xml

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

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

enter image description here

答案 1 :(得分:1)

您可以使用具有渐变颜色和alpha的png图像,将其放在横幅图像的底部。您的姓名文字在图片上。

答案 2 :(得分:0)

创建一个可绘制文件gradient.xml

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

使用ImageView如下图

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:foreground="@drawable/gradient">

        <androidx.appcompat.widget.AppCompatImageView
            android:layout_width="match_parent"
            android:layout_height="240dp"
            android:src="@drawable/ic_launcher_foreground"
            android:adjustViewBounds="true"
            android:scaleType="fitCenter"
            android:id="@+id/imageView"/>
        </FrameLayout>
相关问题