Android background image does not change when orientation

I have a linear layout for my ActivityGroup as defined

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:mtx="http://schemas.android.com/apk/res/com.matriksdata"
  android:id="@+id/homeActivityGroupBG"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:background="@drawable/background">

And I have 2 background pictures located in folders with the ability to draw and "draw." When you change the orientation, everything is fine, but the background does not change in accordance with the orientation. It always saves the very first available for the background.

I tried changing it manually in onConfigurationChangedby adding the line:

background.setBackgroundResource(R.drawable.background);

he solves the problem. But this causes a huge amount of memory leaks every time you change a configuration or when passing through actions.

Edit: I create a .xml theme to define the background image in the window. The XML file contains:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme">
<item name="android:windowBackground">@drawable/background</item>
</style>
</resources>

I changed AndroidManifest.xml as

<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true" android:name="com.matriksdata.app.DefaultApplication"
android:theme="@style/Theme">

. . , , , .

? , ?

: Android, , ActivityGroup

+3
1

, , . xml layout-land/, , . , ( - xml), , !

Android Developer , ; .

+2

Source: https://habr.com/ru/post/1795510/


All Articles