【问题标题】:How to add elevation to transparent ImageView [android]如何将高程添加到透明 ImageView [android]
【发布时间】:2023-03-17 08:39:01
【问题描述】:

真的是用包含透明背景的png来实现ImageView的提升吗?例如:我想给这张照片添加高程阴影:

想要这样:

【问题讨论】:

  • 你解决了吗?
  • @AyushSth 刚刚将其添加为带有阴影的png,如上图所示......那是2015年......也许现在可以正确解决但不确定。

标签: android android-elevation


【解决方案1】:

在您的 XML 中添加:

android:elevation="2dp"    
android:background="@drawable/myrect"

在你的 Drawable 文件夹中添加这个 drawable:

<!-- res/drawable/myrect.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <solid android:color="#42000000" />
    <corners android:radius="5dp" />
</shape>

查看这里了解更多信息:http://developer.android.com/training/material/shadows-clipping.html

【讨论】:

  • 我知道。但它只会在视图周围添加矩形阴影。我只想在 ImageView 中的非透明像素周围添加阴影。
  • 更改半径以匹配对象的半径
  • 它只制作矩形或全圆阴影。
  • 如何在drawable中绘制这个形状?
  • 查看半圆形可绘制对象的答案:stackoverflow.com/questions/15962745/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-18
  • 1970-01-01
  • 2014-10-03
  • 2021-04-12
相关资源
最近更新 更多