如何实现阴影和高程?安卓工作室

问题描述

我已经搜索了几天如何制作这些颜色阴影和高程效果,但在任何地方都不清楚。 最简单的方法是什么?

enter image description here

enter image description here

解决方法

Starting API 28 (Pie) View#setOutlineAmbientShadowColor(int color) 和 View#setOutlineSpotShadowColor(int color) 在 View 类中可用。

如果您在视图上使用高程,则可以使用这两种方法来更改阴影的颜色。

您可以使用 CardView 制作阴影。

,

最简单的方法之一:

卡片视图

卡片视图以及支持高度。

   <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:cardBackgroundColor="@android:color/white"
        app:cardElevation="20dp" />

注意:在卡片视图的背景中,您只能使用简单的颜色。如果您想要更多选项,您可以将您的图片或 drawable 放在子背景中。

像这样:

   <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:cardElevation="20dp" >

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/flag_peru"  <= use this options
>
.
.


</androidx.constraintlayout.widget.ConstraintLayout>


</androidx.cardview.widget.CardView>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...