我的 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">
我在“drawable”和“drawable-land”文件夹中有 2 个背景可绘制对象。当方向改变时,一切正常,但背景不会根据方向改变。它始终保留第一个可绘制的背景。
我尝试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 内存使用问题上提出了一个关于可能使用 ActivityGroup的问题