我有一个ImageView的,我希望它是点击。图像本身只有32×32像素,但我想要的点击范围要大一些,以便更容易打。我希望我可以设置布局边距值增加的ImageView点击区域的大小:
I have an ImageView, and I want it to be clickable. The image itself is only 32x32 pixels, but I want the clickable region to be larger so it's easier to hit. I was hoping I could set the layout margin values to increase the size of the imageview's clickable area:
<ImageView
layout_width="32dip"
layout_height="32dip"
layout_margin="20dip" />
这不工作,有什么我可以做的就是重建图像资源具有较大的透明区域周围。这是一个有点恼人,因为它很难调整,如果我需要更改可点击区域。这不只是一个单一的PNG或者说,它是一个statelistdrawable所以我必须要调整3个不同的png格式,如果我以往任何时候都需要调整可点击区域。
That doesn't work, what I could do is just recreate the image resource to have a larger transparent region around it. That's a bit annoying because it's hard to tweak if I ever need to change the clickable region. It's not just a single png either, it's a statelistdrawable so I have to resize 3 different pngs if I ever need to tweak the clickable area.
我还能做什么?
感谢
建议(从来没有尝试过我自己):
Suggestions (never tried it myself):
创建ImageView的一样大,你想不是把图像转换成它不进行缩放
Create ImageView as large as you want than put image into it without scaling
ImageView.setScaleType(ImageView.ScaleType.CENTER).
强力方法:创建新的更大的PNG,有中心的原始图像和它的其余部分是透明的。
Brute force approach: create new larger png that has original image centered and the rest of it is transparent.