gpt4 book ai didi

android - 高程产生的阴影显示为可绘制的圆形作为背景但不是矩形

转载 作者:行者123 更新时间:2023-11-29 02:22:58 26 4
gpt4 key购买 nike

我正在尝试使用 View 的高程属性来转换阴影。当背景是圆形或可绘制的圆角矩形时,它工作正常。但是,如果我使用颜色或可绘制的矩形作为背景,则不会显示阴影。

只需将圆角矩形的半径更改为零,即可使阴影消失。我已经尝试过类似问题的解决方案,例如添加填充和边距。我添加了两个:

android:clipChildren="false"
android:clipToPadding="false"

到父 View ,但这也没有解决问题。

我正在使用最简单的形状:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/colorAccent" />
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp"/>
<solid android:color="@color/colorAccent" />
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorAccent" />
</shape>

这是我正在测试的非常简单的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="300dp"
android:layout_height="300dp"
android:background="@drawable/rectangle"
android:elevation="40dp"/>
</LinearLayout>

我知道在 Android 中还有其他方法可以实现阴影,例如使用 9 补丁图像,但提升是一种更简单的方法,我希望仅使用它就可以实现它。

这些是仅更改背景可绘制对象的预览。

https://i.imgur.com/CtVhI8m.png https://i.imgur.com/T2Ozcz7.png

这是我想要的最终结果:

https://i.imgur.com/irIMNAF.png

但我主要只是想弄清楚为什么阴影没有以颜色或矩形可绘制对象作为背景显示。

最佳答案

当我使用纯色背景(例如 android:background="#fff")或没有圆角的矩形并运行应用程序时,我看到了阴影。

但是,我必须实际运行该应用。仅查看 Android Studio 布局预览不会显示阴影,除非我使用带圆角的背景可绘制对象。所以我怀疑您只是在查看布局预览的错误(或功能?)。

关于android - 高程产生的阴影显示为可绘制的圆形作为背景但不是矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54079913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com