Android 放置自定义imageView的阴影
我创建了一个简单的播放图标。我将SVG文件导入到Android Studio中,并将其作为imageView来源。然而,不幸的是,我无法从我的Adope XD文档中引入下拉阴影。在这两种情况下,我一直试图通过代码复制下拉阴影效果。然而,我一直不成功 左边的图像是我拥有的,右边的图像是我需要的: 我一直在摆弄现有的代码,但没有成功。以下是我到目前为止的情况: 图像视图:Android 放置自定义imageView的阴影,android,xml,android-imageview,shadow,layer-list,Android,Xml,Android Imageview,Shadow,Layer List,我创建了一个简单的播放图标。我将SVG文件导入到Android Studio中,并将其作为imageView来源。然而,不幸的是,我无法从我的Adope XD文档中引入下拉阴影。在这两种情况下,我一直试图通过代码复制下拉阴影效果。然而,我一直不成功 左边的图像是我拥有的,右边的图像是我需要的: 我一直在摆弄现有的代码,但没有成功。以下是我到目前为止的情况: 图像视图: 要实现这一点,您应该使用CardView。因此,它将类似于: <FrameLayout xmlns:andro
要实现这一点,您应该使用CardView。因此,它将类似于:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#687199"
>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardBackgroundColor="@android:color/transparent"
app:cardCornerRadius="40dp"
app:cardElevation="16dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/test"
/>
</androidx.cardview.widget.CardView>
</FrameLayout>
您只需使用app:cardElevation
和app:cardCornerRadius
即可获得所需的阴影
另外,请记住,当对象靠近屏幕底部时,Android阴影系统会绘制更暗和更长的阴影。我似乎无法使用您的方法获得我想要的确切效果。你能调整你的代码来达到这个效果吗?太棒了!我意识到我的问题来自其他地方,但很明显,你的解决方案确实有效!