Talha Masoud
Talha Masoud

Reputation: 13

How can I define different layouts for both landscapes?

I am trying to define two different layouts for both right landscape and left landscape.. like in a calculator app that both orientations show different buttons. I have tried layout-land but that only works for one landscape layout. I am new to this and this is my first app so please help.

Upvotes: 1

Views: 80

Answers (1)

Hardy
Hardy

Reputation: 2606

-You can make two layout one is for right and another for left and detect the orientation:

private void getScreenRotationOnPhone() {

    final Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    switch (display.getRotation()) {
        case Surface.ROTATION_0:
            System.out.println("SCREEN_ORIENTATION_PORTRAIT");
            break;

        case Surface.ROTATION_90:
            System.out.println("SCREEN_ORIENTATION_LANDSCAPE");
            break;

        case Surface.ROTATION_180:
            System.out.println("SCREEN_ORIENTATION_REVERSE_PORTRAIT");
            break;

        case Surface.ROTATION_270:
            System.out.println("SCREEN_ORIENTATION_REVERSE_LANDSCAPE");
            break;
    }
}

- above code is working to detect the orientation and you can set the layout as per your rotation

-Let me inform or vote it if it was helpful for you thanks!!

Upvotes: 2

Related Questions