通过使用填充展开了ImageView的可点击的区域? [英] Expand clickable area of an ImageView by using padding?

查看:115
本文介绍了通过使用填充展开了ImageView的可点击的区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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):

  1. 创建ImageView的一样大,你想不是把图像转换成它不进行缩放

  1. 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.

    这篇关于通过使用填充展开了ImageView的可点击的区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆