Screenorientation

Asked

Viewed 298 times

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 run it in the emulator, and press the button 9 on the keyboard (to change orientation) back to another layout, the login (main).
What should I do to not make that kind of mistake?

  • It is not quite clear what you are asking. Please further develop your question.

  • I created a layout and put that code where it shows the function to leave only in PORTRAIT mode but when I run the app in the emulator, and test it in LANDSCAPE mode (by pressing the button 6 or 9)to see if it continues in PORTRAIT mode, but the error in which to return to my main layout, which has nothing to do =(

  • Please post the code of Activity where the layout is used. If you are giving any error post also the Logcat. The information you gave is not enough to see where the problem is.

3 answers

1

Experiment with

android:configChanges="orientation"

0

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

Thus, in the declaration of Activity in the manifest, within the tag <activity> you can do the Activity function only in portrait.

However, the most indicated is that you do your own treatment Activity and the orientations of the screen.

0

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

So that this does not occur add this line of code in the application manifest, within the Activity node in question:

android:configChanges="keyboardHidden|orientation"

  • add Aki? <? xml version="1.0" encoding="utf-8"? > <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="br.com.project" android:versionCode="1" android:versionName="1.0" android:configChanges="keyboardHidden|orientation" >

  • I put the code inside the Activity in the manifest and it didn’t work, when I press the key 9 goes to another layout that has nothing to do =(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.