我正在制作一个需要在 ImageView 上设置背景颜色的 android 应用程序。图像是带有透明部分(一种蒙版)的纯白色方 block ,但我看到背景“溢出”了边界,形成了轮廓。我该如何解决?
谢谢!
相关的XML代码如下:
<ImageView
android:id="@+id/tile1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/hexagon"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_marginLeft="@dimen/hexagon_horizontal_margin"
android:layout_marginRight="@dimen/hexagon_horizontal_margin"
android:background="#ffff000b"/>
(hexagon_horizontal_margin
设置为 4dp)
图像是 100x100 像素,这是它在模拟器中的样子:
最佳答案
问题出在您的六边形可绘制对象中。 Drawable 每一侧的外部像素都是透明的。因此,当您将颜色设置为背景时。这些像素让背景颜色显示出来。编辑您的可绘制对象以删除该透明度并完成。
在这里试试这个可绘制对象:
关于android - ImageView 背景太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24769707/