我正在使用 9-patch 为盒子制作阴影。如果图像宽度为 280dp(距离框边缘 20dp),我会得到一个很好的投影(@315 度):
但是,如果我让图像接触到框边缘,右边缘的阴影几乎消失了:
这是我的布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@drawable/dropshadow">
<ImageView
android:id="@+id/frontimage"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_alignParentTop="true"
android:scaleType="center"
/>
...
</RelativeLayout>
这是我正在使用的 9 补丁:
有人知道为什么会这样吗?
谢谢!
最佳答案
将顶部和左侧的黑色边框缩小到 1 px(可拉伸(stretch)区域)。
像这样:
可选地,您还可以将右侧和底部的黑色边框减少一些像素(以引入一些填充)。
像这样:
您可以选择在图像(包括阴影)和黑色边框之间添加一些空白(透明)空间(假设每边 4 像素)。
这将添加一些填充。
或
你可以给你的 RelativeLayout 添加一些 padding
关于android - 当图像接近边缘时,9 补丁阴影消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22049730/