I am using the below code to rotate an ImageView Control
ImageView Iv = new this.findViewById(id)
RotateAnimation a = new RotateAnimation(0, 60);
a.setFillAfter(true);
a.setFillBefore(false);
a.setDuration(0);
Iv.startAnimation(a);
The problem with the above code is that the ImageView looks rotated, but can’t be clicked correctly. The coordinates that trigger the click event are the ones at the area the control had before beeing rotated.
Also I tried another solution,, I tried to write a custom view extends ImageView and rotate the control canvas in onDraw() but this solution did not rotate the control , it rotates the content of the control.
@Override
protected void onDraw(Canvas canvas)
{
canvas.rotate(60, getWidth() / 2, getHeight() / 2);
super.onDraw(canvas);
canvas.save();
canvas.restore();
}
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
any idea how can I rotate the control itself and keep it clickable ?
Thanks in advance,
Animation doesn’t change your views position. It’s a common issue with animation. Please look here.