while moving the view .Its rotation is improper?

Monday, July 7, 2014

I m using translating a view(as shown in code). and with that I have two buttons that rotates(using RotateAnimation) the bar clockwise and anticlockwise.What i want is whatever the location of view would be RotateAnimation should rotate the bar as required.


Problem: But when view is at default location(ie at center) it rotates perfectly. But as view location changes due to its translation. The RotateAnimation doesnot work perfectly.


Code for RotateAnimation with two buttons:


`@Override public void onClick(View arg0) { // TODO Auto-generated method stub



if(arg0==rButton) //rButton is 1st Button
{

anim=new RotateAnimation(0,60, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(100);


}

else //2nd Button Code
{anim=new RotateAnimation(0,-60, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(100);

}

bar.startAnimation(anim);


} Code of translation is simple onTouchListener as shown



@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub

bar.setX((int)arg1.getX()); //bar is view i am talking
return true;
}


Now my question is how to make RotateAnimation to work perfectly when view is not in default location(ie at center)?







http://ift.tt/1xFhrWB