Rotate View Hierarchy 90 Degrees

Rotate View Hierarchy 90 degrees

I had the same problem and managed to solve it.
Instead of rotating each view or the layout by hand, I used a LayoutAnimationController.

First, place a file in /res/anim/ called rotation.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="-90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="0" android:fillAfter="true">
</rotate>

Then, in your Activity's onCreate, do

  @Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

setContentView(R.layout.myscreen);

Animation rotateAnim = AnimationUtils.loadAnimation(this, R.anim.rotation);
LayoutAnimationController animController = new LayoutAnimationController(rotateAnim, 0);
FrameLayout layout = (FrameLayout)findViewById(R.id.MyScreen_ContentLayout);
layout.setLayoutAnimation(animController);
}

If you want to rotate elements that lie above your camera preview view (SurfaceHolder), simply place a FrameLayout above the SurfaceHolder, place all your elements in that FrameLayout and call the Layout "MyScreen_ContentLayout". Done.

Hope that helped someone out, took me quite a while to get everything together.

How to rotate a view in android and also adjust its height in respect to parent view

you can check this library it makes it easy for you: https://github.com/rongi/rotate-layout\
because it has the feature you looking for, The bounding box is rotated with the views inside.

Example

Usage

implementation 'rongi.rotate-layout:rotate-layout:3.0.0'
<com.github.rongi.rotate_layout.layout.RotateLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:angle="90"> <!-- Specify rotate angle here -->

<YourLayoutHere
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</YourLayoutHere>
</com.github.rongi.rotate_layout.layout.RotateLayout>

Android rotate a View only by 90 degrees

You may not want to change to landscape, but that doesn't change the fact that it's the right answer. ;)

Honeycomb devices use the current orientation to orient the system bar at the bottom of the screen even when your app asks for full-screen mode. This is also used to orient screenshots for the recent task switcher, and it will probably continue to be used for more things like this in the future.

You can write a trivial custom parent view that will rotate the measurement, layout, and drawing to handle your current problem, but the right answer is still to run your app in landscape mode. Your app will be broken in a number of ways that you will not be able to hack around if you continue down this path.

Android View Rotation Animation and Set Rotation not working as intended

take global variables- float rotation = 0,fromRotation=0;

and on Onclick

            fromRotation=rotation;
rotation = rotation + 90;
RotatePoint(rotation);

and RotatePoint(float toDegrees)

RotateAnimation rotate = new RotateAnimation(fromRotation, toDegrees,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(1000);

rotate.setFillAfter(true);
pt.startAnimation(rotate);


Related Topics



Leave a reply



Submit