ScreenOrientation

0

I created a layout and in it I put the following code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:screenOrientation="portrait"
  >
<TextView
       android:id="@+id/textView1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginLeft="5dp"
       android:text="Teste de Orientação"
       android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

BUT when I squeeze it in the emulator, and I press the 9 button on the keyboard (to change orientation) it returns to another layout , the login (main). What should I do to not give this type of error?

    
asked by anonymous 27.03.2014 / 20:44

3 answers

1

Try with

android:configChanges="orientation"

    
11.04.2014 / 15:18
0

The problem is that when you change the orientation of the screen the Activity is recreated. See more about it here

For this to happen, add this line of code to the application manifest, within the Activity node in question:

android:configChanges="keyboardHidden|orientation"

    
27.03.2014 / 21:36
0
<activity
    android:name="br.com.exemplo.seuapp.MinhaActivity"
    android:label="@string/title_activity_minha"
    android:screenOrientation="portrait" >
</activity>

This way, in the declaration of the Activity in the manifest, inside the tag <activity> you can make the Activity work only in portrait .

However, it is best to treat your% of% and screen directions.

    
11.04.2014 / 15:04