how to rotate a whole relative layout in android
I am developing android application. I need to rotate a whole layout when the user touch and drag image in layout. I am using relative layout. In this i am having one image view and drag button and one image as background for relative layout. Now i need to rotate the whole relative layout when drag button is in move.
While trying with rotate animation, it runs at once after that touch event is not sensing. I added my code as below
anim = new RotateAnimation(0, -15f, Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 0f);
anim.setInterpolator(new LinearInterpolator());
anim.setDuration(700);
anim.setFillAfter(true);
anim.setAnimation开发者_StackOverflowListener(MainActivity.this);
rotationctrl.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
innerlayout.startAnimation(anim);
}
else if (event.getAction() == MotionEvent.ACTION_MOVE) {
} else if (event.getAction() == MotionEvent.ACTION_UP) {
}
return true;
}
});
whats the problem here. where i doing mistake.. please help me.
Android animations only shifts the pixels of the UI layouts when you add animations to them. To actually update the layout after the animation, you should implement an animation listener and manually update the layout other wise the old layout will still remain with the only the pixels shifted.
So if you dont manually update the layout, the image and its response area will be in the old position even though it is not visible.
精彩评论