我有一个线性布局用于我的ActivityGroup,如下所定义
<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">
我有2个背景图像,分别位于“ drawable”和“ drawable-land”文件夹中。当方向改变时,一切都正常,但背景不会根据方向改变。它始终保持第一个背景可用作背景。
我尝试在onConfigurationChanged
方法中手动更改它,添加以下代码:
background.setBackgroundResource(R.drawable.background);
它解决了问题。但每次配置更改或通过活动时都会导致大量内存泄漏。
编辑:我创建了一个theme.xml文件来定义窗口的背景图像。XML文件包含:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme">
<item name="android:windowBackground">@drawable/background</item>
</style>
</resources>
我将AndroidManifest.xml更改为:
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true" android:name="com.matriksdata.app.DefaultApplication"
android:theme="@style/Theme">
我从布局中删除了背景元素,但是没有任何变化。当设备方向改变时,我无法获得新的可绘制对象,并且出现了内存泄漏,最终导致应用程序崩溃。
有没有其他方法可以强制更改可绘制对象的方向?或者应用程序产生内存泄漏的原因是什么?
编辑:关于内存泄漏问题,我在Android Memory Usage Problem on possibly using ActivityGroup上提出了问题。
drawable-port/
而不是drawable/
吗? - bigstones