I am about to leave a project and wanted to add a little Easter egg to the app. I was just wondering, is it possible to rotate the whole screen 360 degrees on a button click say? Or is this too hard?
I was potentially thinking you could take a screenshot, rotate that screenshot 360 degrees, and then delete it. But I'm not sure about the security implications of taking a screenshot the users phone
You could specify an id in your root layout (e.g #+id/main) and use a classic animation like this
final RotateAnimation rotateAnimation = new RotateAnimation(0.0f, 360.0f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(500);
findViewById(R.id.main).startAnimation(rotateAnimation);
Related
I am making a Rollette game and I want to play sound in each crossing section like if 1 is crossing it should find some trigger or collision detection and ping one tick sound. My problem is that I am not able to find the collision detection on image. Below is the approaches that I have done.
I have taken LayoutView and placed a Rollette wheel image inside it.
In each section (0-9) has taken a green small button which will be used to detect the collision with the arrow. Once it collides there will be a Tick sound with up-down animation in arrow. (Image attached).
Problem.
I am not able to find the new co-ordinate of views in each rotation. It is returning the same static location every time and hence collision is never happening.
Rotation Code..
final RotateAnimation rotate = new RotateAnimation(0, 360f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(10000);
rotate.setFillAfter(true);
Collision detection code...
Rect arrowBtnRect = new Rect();
arrowBtn.getGlobalVisibleRect(arrowBtnRect);
Rect btn0Rect = new Rect();
btn0.getGlobalVisibleRect(btn0Rect);
if(arrowBtnRect.intersect(btn0Rect)) {
System.out.println("Collision detected "+numberSelected);
numberSelected = "0";
return true;
}
Your idea is brilliant!
But I have certain remarks on your approach:
setFillAfter() is not helping, according to documentations:
If fillAfter is true, the transformation that this animation performed will persist when it is finished.
I recommend using ObjectAnimator instead of RotateAnimation. While RotateAnimation is just making the view looks as if it is rotating until you call fillAfter (which happens after animation stops), ObjectAnimator makes the view really change its actual angle while rotating. See this: https://stackoverflow.com/a/29465710/10005752
Usage:
Random random = new Random();
float randomAngle = (float) (random.nextInt(360) + 1);
ObjectAnimator rouletteAnimator = ObjectAnimator.ofFloat(rouletteView, View.ROTATION, 0f, randomAngle);
rouletteAnimator.setDuration(10000);
rouletteAnimator.start();
Also, to elaborate more on my comment I recommend that get all angles that have buttons on them before starting animating, and when animation starts keep using rouletteView.getRotation(); to check what angle is at the top.
Example:
Button1 is at angle 90 and rouletteView is rotating Counter Clockwise. Then if rouletteView.getRotation() == 360 - 90 is true then Button1 is touching the arrow.
I hope I'm clear!
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);
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();
I have a custom built compass that is used as part of a navigation app that I have written. I have also written an algorithm that that smooths out the compass (a type of low-pass filter). Everything works great and the compass is fluid. I pass in a current degrees and previous degrees arguments to the RotateAnimation. Problem is when you spin around quickly with the compass, after a certain point, the gap is so large between the current and previous degrees that the rotate switches direction to the path of least distance. It has to do with the sort of lag that happens from the low-pass filter - that it has to catch up wit the real-time direction. I was wondering if anyone has dealt with this (I have seen some compass apps from the store that handle this) or has some kind of algorithm/solution, to keep the orientation of the rotation. Here is some code:
RotateAnimation rotate = new RotateAnimation(startingPointer, pointerDeg, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setInterpolator(new LinearInterpolator());
rotate.setDuration(ROTATION_INTERVAL);
rotate.setFillAfter(true);
pointer.setAnimation(rotate);
startingPointer = pointerDeg;
In my application, I am rotating a clock hand to the desired amount of minutes. This works good with RotateAnimation. Now what I want to do is to return the hand back to the starting position (0 minutes).
For example:
I first rotate the hand like this:
final RotateAnimation anim = new RotateAnimation(0f, ammountDegress, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 1f);
anim.setFillAfter(true);
anim.setFillEnabled(true)
Then I would like to move the hand back to it's starting position, so that means I should be calling a RotateAnimation after the first animation ends.
The problem is that the pivots have changed, how I can I set the pivot position to the exact position as previous? So that the rotating point is again at the same position of the clock hand.
Edit To make it more clearer - I would like to have something like a fixed point pivot that doesn't change with the rotation, so I am always rotating the hand around the same point.
I hope you can understand what I mean.