activity Splash Screen only vertical, login activity start vertically by default


I have two activities:

  • It's my splash screen
  • It's my login
  • I need my splash screen (activity 1), only handle the vertical position, it lasts 5 seconds my splash screen. Immediately after the login starts (activity 2) but I need that although the phone is in a horizontal position the login (activity 2) starts in the vertical position by default (I was already made that observation by users and the login is bad, besides that it should not be allowed on phones).

    I can not block the horizontal position in this activity because I have code that allows the use of the tablet both in vertical and horizontal position, I tried this, but I'm sure I'm only allowing vertical orientation on both the phone and the tablet and for now I do not have a tablet on hand to verify my theory, what could I do?

    asked by Juan Lopez 01.04.2016 в 06:08

    4 answers


    This question can be said to have been previously answered, since it applies to Xamarin as well:

    Deactivate screen rotation on android

    You can do it with the property screenOrientation within your AndroidManifest.xml .

    <activity android:name=".SplashScreen"
        android:screenOrientation="portrait" />

    This ensures that your Splash screen always starts in vertical orientation.

    answered by 01.04.2016 в 17:49

    You can add android:screenOrientation="portrait" in your AndroidManifest.xml file:

    <activity android:name=".MiActividad"

    With this you will make your activity only stay horizontal always, now well if you do not want to put it in the file AndroidManifest.xml you can use:

    setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    So you can always set your activity horizontally, you could use a validation set to know if it is a tablet or a smartphone taking the size of the screen in this way:

    DisplayMetrics metrics = new DisplayMetrics();
    int ancho = metrics.widthPixels;
    int alto = metrics.heightPixels;
    float xdpi = metrics.xdpi;
    float ydpi = metrics.ydpi;

    It would be a matter of validating your needs.

    answered by 01.04.2016 в 07:16

    It's very simple you just have to put this line of code inside the tag in your androidManifest.xml file android: screenOrientation="portrait" >

    So your Manifiest would look like this

                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

    answered by 01.04.2016 в 07:17

    I would suggest two things:

    Put only the screen orientation attribute in the splash, because it is the one that should always be fixed.

    [Activity(Label = "Ejemplo-Splash", ScreenOrientation = ScreenOrientation.Portrait)]

    And in the second, directly do not use any guidance

    [Activity(Label = "Ejemplo-MiVista")]

    Use the SetRequestedOrientation() method in the OnCreate() to set the orientation you need by default. Then, when necessary, you can reuse the method to set the orientation as you prefer.

    To start the values depending on the device, take a look at this link. The idea is to have a Boolean condition that tells you which orientation to assign using value resources.

    P.D: If you do not have a device at hand, you can always use Genymotion ; I've always been better than any other emulator, you have images of phones and tablets, and you can emulate the change of orientation;)

    answered by 20.10.2016 в 23:43