topher
topher

Reputation: 1397

Increase an Image's clickable area

Edit: I am using LibGDX framework.

There is an Image Actor, which is:

This Image's touchable area is fixed on the image's width and height.
I want to increase the touchable area by N pixels.
How can I achieve this?

Here's an illustration: (red rectangle = touchable/clickable area)

enter image description here

Upvotes: 2

Views: 341

Answers (2)

Ankur Aggarwal
Ankur Aggarwal

Reputation: 2220

The way I would approach it, is to have a custom image view, with the actual Image View inside a RelativeLayout. The relative layout has padding and/or margin set, so that it is bigger than the imageView. then, when you set the onClicklistener, set it on the relative layout as well as the image layout (in your custom class)

Upvotes: 1

noone
noone

Reputation: 19776

Image already supports this out of the box. The actor can be bigger than the drawn image itself. You can supply a Scaling strategy for the drawn picture and in case you use Scaling.none, the drawn picture will be independent of the actor's size.

image.setScaling(Scaling.none)
int N = 30;
image.setSize(image.getImageWidth() + N, image.getImageHeight() + N);

Upvotes: 1

Related Questions