【问题标题】:How to give effect to ImageView如何使 ImageView 生效
【发布时间】:2019-08-25 20:02:17
【问题描述】:

期望:

我想在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>

但它不起作用。有什么解决办法吗?

【问题讨论】:

  • 看看this
  • 放置一个从暗到透明渐变的图层

标签: android xml android-layout imageview


【解决方案1】:

活动或片段的布局

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

可绘制的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>

根据需求改变颜色

【讨论】:

    猜你喜欢
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 2018-07-05
    • 1970-01-01
    相关资源
    最近更新 更多