androidthings / sample-button

Basic input and output using a button and LED

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Screen Orientation

danilobertelli opened this issue · comments

Hello guys,

That's actually not an issue, but I was not able to find the answer.
Is there any way to rotate screen? I mean, I would like to rotate my monitor 90º, I already tried to add the screenrotation on manifest but without success.

Is that possible?

Thanks in advance!

Hello all,

I was able to do a workaround for this issue while there's no beautiful way.

The idea was to rotate your activity layout.

    public static void rotateScreen(final RelativeLayout layout, final Activity activity) {

        Display display = activity.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int w = size.x;
        int h = size.y;

        layout.setRotation(90.0f);
        layout.setTranslationX((w - h) / 2);
        layout.setTranslationY((h - w) / 2);

        ViewGroup.LayoutParams lp = layout.getLayoutParams();
        lp.height = w;
        lp.width = h;
        layout.setLayoutParams(lp);
        layout.requestLayout();
    }

My main layout is a Relative, but you can generalize and do it for any one.

Thanks!

Have you tried to use android:screenOrientation="portrait" or android:screenOrientation="reversePortrait" on your in AndroidManifest.xml?