-1

I've one major issue. I built one chat app from scratch using Firebase, Java and Android, which contains many activities and class. Now suddenly I found that I forgot to set UI for Landscape mode (which is like default tablet mode). I opened my app and rotate to landscape, and UI looks very bad, even some part is not visible. I'm actually planning to publish on play store just for learning purpose. So is there any easy way to do this?

  • Should I restrict, so that user not able to rotate the screen for every activity like below is mation in either java or xml through?

In XML:

<activity android:name=".SomeActivity"
           android:label="@string/app_name"
           android:screenOrientation="portrait">

In Java:

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  • I also don't know that how can I do this for all activity? Should I have to crate duplicate activities for all activity? and how can I do this? where can I attach? I really don't have any idea about this. Please help me.
ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
  • You have to add `layout-land` directory in your `res` directory and then copy paste all the `layout` XML files(only those which are misbehaving when in landscape mode) and then edit each one of them. – codeconscious Jul 19 '18 at 18:13
  • It means I have to create almost all activities and change the UI? And How can I attach this new layout xml in Activity? – Ruchika Singh Jul 19 '18 at 18:19
  • No not the activities only the XML files which misbehave. Android will implicitly link the files in `layout-land` directory with your activities and if you have not provided then it will use main `layout` directory. https://stackoverflow.com/a/5407784/5954246 – codeconscious Jul 19 '18 at 18:24

1 Answers1

0

Studio generates layout for you just adjust the generated layout as per need and that layout will be used automatically

Should I restrict, so that user not able to rotate the screen for every activity like below is mation in either java or xml through?

You shouldn't restrict user to one orientation, If design specs of you layout is ideal for landscape then go for it

I also don't know that how can I do this for all activity? Should I have to crate duplicate activities for all activity? and how can I do this? where can I attach? I really don't have any idea about this. Please help me.

With manifest solution, yes, you have to do this for every activity entry in manifest file.

either do it via manifest or via xml.

To set orientation of all activities, you can create a base activity and extend all activities from it where your base activity set the orientation. e.g

// no need to set orientation in manifest
class BaseActivity extends AppCompactActivity{

    oncreate(...){
     super.oncreate(..);
     setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}

class YourOtherActivities extends BaseActivity{

    oncreate(...){
       super.oncreate(..);
       setContentView(..);
    }

}
Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68