android - 当图像接近边缘时,9 补丁阴影消失

标签 android android-layout

我正在使用 9-patch 为盒子制作阴影。如果图像宽度为 280dp(距离框边缘 20dp),我会得到一个很好的投影(@315 度):

enter image description here

但是,如果我让图像接触到框边缘,右边缘的阴影几乎消失了:

enter image description here

这是我的布局:

<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 补丁:

enter image description here

有人知道为什么会这样吗?

谢谢!

最佳答案

将顶部和左侧的黑色边框缩小到 1 px(可拉伸(stretch)区域)。

像这样:

enter image description here

可选地,您还可以将右侧和底部的黑色边框减少一些像素(以引入一些填充)。

像这样:

enter image description here

您可以选择在图像(包括阴影)和黑色边框之间添加一些空白(透明)空间(假设每边 4 像素)。
这将添加一些填充。

你可以给你的 RelativeLayout 添加一些 padding

关于android - 当图像接近边缘时,9 补丁阴影消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22049730/

相关文章:

java - 如何让你的应用程序谷歌搜索一些东西?

android - 如何处理 RecyclerView 中的多个倒数计时器?

android - 请帮我看一下 Android 记事本教程

android - CollapsingToolbarLayout 不随 ScrollView 滚动

android - 在按钮上,文本和可绘制对象在居中时距离太远

android - 在添加到 android.R.id.content 的 Fragment 中未调用 onStop

android - 单击 TextView 时显示 ArrayAdapter

android - 创建覆盖大多数 Android 设备的布局集

android - ConstraintLayout 的任何布局管理器?

android - 无法访问 AlertDialog 内的 View