这里有点类似的问题,但答案是只删除海拔和阴影......不是我想要的:Android CardView 透明时有奇怪的边框 https://stackoverflow.com/questions/31624085/android-cardview-with-weird-border-when-transparent/31624267
我想要的是 Pixel Launcher 搜索栏中显示的内容......即具有半透明背景和阴影的形状,但是阴影不与白色形状重叠(这最终会使它看起来是灰色的)。我基本上想要一个阴影,但在它的中间有一个洞,我的形状就是......
This is what I want to achieve (the search bar down the bottom):
这是我尝试过的,但您可以从附图中看到,灰色阴影穿过半透明的白色背景。
活动主文件
<FrameLayout
android:layout_width="120dp"
android:layout_height="120dp"
android:background="@drawable/rectangle"
android:elevation="8dp" />
矩形.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="4dp" />
<solid android:color="#aaffffff" />
</shape>
This is what my attempt looks like:
你可以看到,尽管我的形状是白色背景上的半透明白色,但由于下面的阴影,它变成了灰色,这不是我想要的。
我也尝试使用 View#setOutlineProvider 但没有成功。
我也尝试过玩https://github.com/harjot-oberai/MaterialShadows https://github.com/harjot-oberai/MaterialShadows
如果可以避免的话,我不想用 9patch 图像来做。