2

I have a very strange problem: i have an activity with EditText and three buttons and two layout files for handling orientation change. When i start an app in portrait orientation and rotate the device android preserves the portrait orientation layout, but if i start an app in landscape orientation android loads an appropriate landscape layout file, but again preserves landscape layout even after rotating to portrait layout. This happens only with activity containing EditText. What's wrong? Here's my code: 1) Manifest.xml:

  <activity
        android:name=".AnalyzeTextActivity"
        android:configChanges="orientation|screenSize|screenLayout"
        android:parentActivityName=".StartScreenActivity"
        android:windowSoftInputMode="adjustPan"
        />

2) portrait

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_analyze_text"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ADD5F7"
    android:clickable="true"
    android:focusableInTouchMode="true"
    >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:gravity="start"
        android:id="@+id/edit_text_analysis"
        android:hint="@string/edit_text_hint"
        android:isScrollContainer="true"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:id="@+id/button_upload_file"
        android:background="@drawable/button_upload_large"
        android:onClick="onUploadClicked"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/button_upload_file"
        android:layout_marginTop="10dp"
        android:id="@+id/button_start_analysis"
        android:background="@drawable/button_start_large"
        android:onClick="onStartClicked"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/button_start_analysis"
        android:layout_marginTop="50dp"
        android:background="@drawable/button_clear_large"
        android:onClick="onClearClicked"/>

</RelativeLayout>

3) landscape

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_analyze_text"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ADD5F7"
    android:clickable="true"
    android:focusableInTouchMode="true"
    >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:gravity="start"
        android:id="@+id/edit_text_analysis"
        android:hint="@string/edit_text_hint"
        android:isScrollContainer="true"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/edit_text_analysis"
        android:layout_toLeftOf="@+id/button_start_analysis"
        android:layout_marginRight="5dp"
        android:id="@+id/button_upload_file"
        android:layout_marginTop="2dp"
        android:background="@drawable/button_upload_small"
        android:onClick="onUploadClicked"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/edit_text_analysis"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="2dp"
        android:id="@+id/button_start_analysis"
        android:background="@drawable/button_start_small"
        android:onClick="onStartClicked"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/edit_text_analysis"
        android:layout_toRightOf="@+id/button_start_analysis"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="2dp"
        android:background="@drawable/button_clear_small"
        android:onClick="onClearClicked"/>

</RelativeLayout>
fregomene
  • 155
  • 1
  • 11

2 Answers2

0

The problem is in the manifest file

android:configChanges="orientation|screenSize|screenLayout"

By default configuration changes handle by android, when you define android:configChanges in the manifest file then you told android that you will handle all confiChanges in brackets inside your activity, there is special method for that

 @Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

To fix your problem just remove orientation from your manifest

android:configChanges="screenSize|screenLayout"
Volodymyr
  • 6,393
  • 4
  • 53
  • 84
  • @ Volodymyr Khodonovych right you are, when i remove orientation from manifest, android loads correct layout file, but i need orientation in my manifest file to preserve ProgressDialog when changing orientation. Any other suggestions? – fregomene Nov 22 '16 at 20:12
  • Check this question there are few possible approaches http://stackoverflow.com/questions/1111980/how-to-handle-screen-orientation-change-when-progress-dialog-and-background-thre – Volodymyr Nov 22 '16 at 20:25
0

Remove android:configChanges="screenSize|screenLayout" from

  `<activity
    android:name=".AnalyzeTextActivity"
    android:configChanges="orientation|screenSize|screenLayout"
    android:parentActivityName=".StartScreenActivity"
    android:windowSoftInputMode="adjustPan"
    />`
Adnan Bin Mustafa
  • 1,229
  • 10
  • 20
  • the same problem - when removing line you suggest i destroy my ProgressDialog. I just need layot files to load properly and ProgressDialog alive. – fregomene Nov 22 '16 at 20:37
  • Have a look on this solution [Prevent dialog dismissal on screen rotation in Android](http://stackoverflow.com/a/15729764/4770978) . – Adnan Bin Mustafa Nov 22 '16 at 20:49