simple question I cant find the answer anywhere, is there a way to rotate a spinner, without rotating screen or anything just create a spinner which is rotated 90 degrees?
Thanks in advance.
On API Level 11+, you are welcome to rotate any View via android:rotation in your layout XML or setRotation() in Java. Whether this will give you something that your users will like, I cannot say.
Programmatically you can try something like this -
RotateAnimation animation = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
// Adding the time needed to rotate the image
animation.setDuration(250);
// Set the animation to stop after reaching the desired position. Without this it would return to the original state.
animation.setFillAfter(true);
//Then set the animation to your view
view.startAnimation(animation);
Related
I am using RotateAnimation to rotate the imageView to -30 degrees. And it works good. Now I change the position of the view by setting different values for X and Y. All good until now.
Now when I perform the same RotateAnimation again to this view after the position changed, it works weird (see the video link below) and I cannot find the reason. I have tried a lot but without success. It seems like related to the pivotX and pivotY after changing the position but I cannot find the actual cause.
Code for RotateAnimation
final RotateAnimation rotateAnim = new RotateAnimation(0f, -30f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 1f);
rotateAnim.setDuration(2000);
rotateAnim.setFillAfter(false);
ivFace.startAnimation(rotateAnim);
Code of changing the position of an imageview
ivFace.setX(300);
ivFace.setY(200);
Here I am posting the video also for better understanding
https://www.youtube.com/watch?v=uVWlrTNDKCM
Looks like the RotationAnimation is still rotating around the 'old' view position, probably because it is 'final' and thats why it is tied to the Views 'old' position the moment it is created. You could create a new RotationAnimation for every position change, which might solve the issue, although I would suggest using ViewPropertyAnimator and/or ObjectAnimator for both, translating your View to another position and rotating it.
As I said I have a textView and I want to rotate it 90 degree.
Problem is I don´t understand where I can set the fixed point.
I use this function
myTextView.animate().rotation(90).setDuration(1000).start();
this does rotate my view but it is always a little bit transformed in one direction.
My end result I want to be that here where the buttom of the text was befor now the right side of the text should be. and there where the left side was I now want the buttom.
Does anybody know how I can do that.
If nothing works I can use transformations to get the text at the right position but I don´t know whow large the text is and so I don´t know how to get the values for the transformation.
RotateAnimation rotate = new RotateAnimation(0, 90,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
rotate.setDuration(4000);
rotate.setRepeatCount(Animation.INFINITE);
yourView.setAnimation(rotate);
For more detail check LINK
use this
RotateAnimation rotateAnmi = (RotateAnimation) AnimationUtils.loadAnimation(this,R.drawable.rorate);
rotateTv.setAnimation(rotateAnmi);
rotateTv.setGravity(Gravity.AXIS_X_SHIFT);
rotateTv.setText();
As the title suggests, I would like to know programmatically if a given View has been rotated already. Here is my animation function:
public static void AnimateArrowDown(View v)
{
RotateAnimation anim = new RotateAnimation(0.0f, 90.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setInterpolator(new LinearInterpolator());
anim.setDuration(200);
anim.setFillAfter(true);
v.findViewById(R.id.arrow_imageview).startAnimation(anim);
}
I'm animating an arrow right to down inside a ListView. My problem is when the view is redraw for some list elements the arrow previously rotated for another list item gets passed to this new list item. Hence, I would like to determine if the arrow in the ListView has been rotated and if so then rotate the arrow to its actual position.
You can use View.getRotation method.
float rotation = v.findViewById(R.id.arrow_imageview).getRotation();
Then you can determine the value is default (0.0f; not rotated) or not (90.0f; rotated).
(Note: However, I would also prefer another approach using state flags like Saehun Sean Oh mentions in his comment. I don't think they need to be static but to be field members, and keep boolean states there.)
I have a problem and I just can't manage to find a solution that works.
So, here is my problem. I have to make an ImageView to rotate itself, to 90 degree on orientation change.
I did that, and the image is actually rotating pretty awesome, but when the animation finishes, the image reset itself to previous position.
Here is the code I used to rotate the image:
Matrix matrix = mImageView.getImageMatrix();
RectF dst = new RectF();
matrix.mapRect(dst, new RectF(mImageView.getDrawable().getBounds()));
mAnimation = new RotateAnimation(0.0f, -90.0f, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
mAnimation.setDuration(5000);
mImageView.startAnimation(mAnimation);
mImageView.setImageMatrix(matrix);
mCurrentOrientation = 1;
you can use this to animation persist after it has been done:
mAnimation.setFillEnabled(true);
mAnimation.setFillAfter(true);
One thing you can do is set the imageview to an already rotated version of the image and then rotate it from -90 to 0 degrees. That will work with the API you are already using. If you make the two calls, one right after it will work correctly without stutter.
The other option is to use a later API version. The Object Animator animations do not return the view to it's original position. More on this here.
How to rotate a drawable by ObjectAnimator?
The code is simple, but this doesn't work with gingerbread.
I am trying to make my own progressdialog, sort of. I'm just using a Dialog which inflates a Layout. In this layout, I have an ImageView, this imageview should rotate just like the original spinner in the ProgressDialog. I applied this animation to it:
RotateAnimation r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
r.setDuration(10000);
r.setRepeatCount(r.INFINITE);
icon.startAnimation(r);
The animation last for 10000 ms obviously. The animation start slowly and ends slowly, is it possible that the rotation speed is constant at all time?
You can set a LinearInterpolator to the animation:
r.setInterpolator(new LinearInterpolator());
A way to increase speed rotation is to set a duration and a number in repeatCount field that apply to you. Doing so, you can control the speed... Just put some big big numbers and add a listener to your animation and when it ends, start it again if dialog is still displayed.