Android - Rotate Admob view 90 degrees? - android

I have been working 2 days to make Admob view displays vertically on my landscape game, the problem seemed to be straightforward, just rotate the view 90 degrees. The first try was to call setRotation(90), I had a crash on my 2.3.4 device because the method is not available untill Android 11. The second try was to use rotation animation, the view did rotate but it get clipped to its original bounds and furthermore it accepts touches as if it was not rotated :(. Finally I found a way to solve the clipped view problem, just call setLayoutParams(width, height) - with width and height large enought, on all the child view of admob view. The problem of touches still unresolved :)
I'm very frustrated, why Android needs a very complex solution for a very simple problem ? In iOS, I just need to apply a rotation transformation to the view and nothing more !
Please help me !
Any suggestion are welcome :)

RotateAnimation rotate = new RotateAnimation(0, 90, admobView.getWidth() / 2, admobView.getHeight() / 2);
rotate.setDuration(500);
rotate.setRepeatCount(0);
rotate.setFillAfter(true);
admobView.startAnimation(rotate);

Related

Drawing application with resize when orientation is changed

I'm sorry to disturb, but at this point, i'm really stuck.
I'm trying to make an activity to draw on a picture. But i've no idea how to handle the rotation of the device.
If i change the bitmap with createScaledBitmap, that works but the draws are not in the right place. (The bitmap is bigger and added space)
I need to stretch the bitmap for the new size (in a way that draws are on the right place on the picture).
Everytime my configuration change, i do that :
snapshotCanvas.mTempBitmap = Bitmap.createScaledBitmap(snapshotCanvas.mOriginalBitmap.copy(snapshotCanvas.mOriginalBitmap.getConfig(), true), drawView1.getWidth(), drawView1.getHeight(), false);
snapshotCanvas.mCanvas.setBitmap(snapshotCanvas.mTempBitmap);
snapshotCanvas.mCanvas.scale((float) snapshotCanvas.mCanvas.getWidth() / drawView.getWidth(),
(float) snapshotCanvas.mCanvas.getHeight() / drawView.getHeight());
I tried many things but i got terribly lost.
Thanks in advance.

Android: Second 180 degree rotation of imageview around Y mirrors the image

I'm trying to make an imageview rotate around it's Y axis, similar to a card flipping, but it should have the same picture on both sides.
To do this, I use an ObjectAnimator in an AnimationSet (though this happens when the Y rotation is the only animation in the set, as well as when it's combined with other animations) to rotate it from 0 to -180 around Y axis. This works fine the first time. However, if I click it again, the image will suddenly get mirrored then rotate 180 degrees around Y axis.
How come the image gets mirrored/reversed before animating? My current idea is that it retains some property, so while it first goes from 0 to -180, next time it will jump from -180 to 0, then rotate from 0 to -180 again. I'm not sure if that is the cause, however if it is, how can I work around this and prevent it from happening?
Thanks!
If i understand you right, this happens because ObjectAnimator doesn't actually applies final value itself. You have to use AnimationListener and onAnimationEnd to save view's state.

Rotating a view on Android issue

I have been stuck on quite an irritating problem for a number of days now.
To describe the problem; I essentially have a issue when I perform a rotation on a view which is part of a larger view, then I display a fragment on top of this view, and then hide this fragment returning to the original view.
The view maintains its rotation but is placed above and to the right of where it should be.
In the XML layout I have set the view to be centered in the parent, and sure enough on startup everything is where its supposed to be.
While the view is rotating and the main view is visible (it is essentially a compass) everything works as intended
If I do not rotate the view, then show the fragment followed by hiding it it stays where it was meant to be without issue, so clearly the act of rotating it and then displaying something over it is causing a problem.
If I continue to rotate the view after it has moved out of position, it snaps back into its centered position and all is well - how can I ensure the view to always remain where its suppose to be?!?
For reference I am calling the rotation method like so:
RotateAnimation rotate = new RotateAnimation(PREVOIUS_ROTATION_AMOUNT, NEW_ROTATION, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(980);
rotate.setRepeatCount(0);
rotate.setFillAfter(true);
compassView.startAnimation(rotate);
This code should do what you're expecting:
compassView.setPivotX(compassView.getMeasuredWidth() / 2);
compassView.setPivotY(compassView.getMeasuredHeight() / 2);
compassView.animate().rotation(NEW_ROTATION).setDuration(980);

image flip effect using animation in android

I'm currently working on an Android game
I want to create an image flip effect using animation.
How would I do it?
There is a good example of such here
try this:
Android Animation - Flip
or more complex:
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html
I managed to achieve this using setScaleX (for flip/reflection around the Y axis). Use setScaleY for flip/reflection around the X axis.
final ValueAnimator rotation = ValueAnimator.ofFloat(0, 360);
Then in your onAnimationUpdate function, set scale on X or Y using the cosine function on your range of angles.
view.setScaleX((float)Math.cos(Math.toRadians((Float)valueAnimator.getAnimatedValue())));
Hope this helps

android.graphics.camera Error

I am developing an Android app on eclipse and have been using android.graphics.camera to 3d transform images. In a nutshell, my app takes a 2d image and gives it perspective. My problem is that I also want to rotate the image around the screen while it is being transformed.
final Matrix mMatrix = canvas.getMatrix();
canvas.save();
mCamera.save();
mCamera.rotateX(60);
mCamera.rotateY(0);
mCamera.rotateZ(0);
mCamera.getMatrix(mMatrix);
mMatrix.preTranslate(-this.gridWidth / 2, -this.gridHeight);
mMatrix.postTranslate(this.gridWidth / 2, this.gridHeight);
canvas.concat(mMatrix);
mCamera.restore();
//Draw and move image here
canvas.restore();
When the image gets to the bottom of the screen, where the camera is translated, the image becomes distorted. I see pieces of it on the screen but its like its being drawn backwards or sideways. I've also tried rotating the image using the rotateZ property but the same effect occurs. Once the image gets 'behind' the translation point, it just goes nuts.
I thought it might be an emulator bug so I loaded it on my Droid X and Acer Iconia and the effect remains the same.
I haven't seen anybody else have this problem so i figured someone here might have a clue as to what's going on.
Any Ideas?
This issue can be addressed with newer versions of Android that let you change the camera distance:
http://developer.android.com/reference/android/graphics/Camera.html#setLocation(float, float, float)

Categories

Resources