【发布时间】:2015-05-10 13:42:50
【问题描述】:
我目前正在开发一个 Android 项目,该项目需要我将图像作为某些活动的背景。我正在使用 Android Studio 开发该应用,并已在多台设备上测试了该应用。
起初我把背景图片放在drawable文件夹中。由于重新缩放图像,这导致帧率下降。在此之后,我将图像放在 drawable-nodpi 文件夹中。 我在摩托罗拉 Moto G (Android L)、Nexus 5 (Android L) 和 Nexus 9 (Android L) 上测试了该应用,一切正常。
为了确保该应用适用于多种设备,我通过 Android Studio 启动了一个 mdpi Jellybean 模拟器。令人惊讶的是,背景只加载到 2/4 活动中(都使用相同的资源)。经过一些研究,我决定预先缩放背景并将其放置在 drawable-mdpi、drawable-ldpi 文件夹等中。再次测试,现在背景只是没有出现在 1 个活动中。我决定在多台设备上使用较旧的 api 进行测试。我发现我的应用在每台 API 低于 Android L 的设备上都有这个问题。
有人可以向我解释一下这是怎么可能的吗,因为所有活动都使用相同的资源?
亲切的问候,
朱尔
学生 ICT 软件开发
编辑 我在 Drawable 文件夹中添加了背景。
加载后台的activity源码
<RelativeLayout 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"
tools:context="nl.beachbash.beachbash.InfoListActivity"
android:background="@drawable/background"
android:backgroundTint="#32dd6800"
android:backgroundTintMode="src_over"
android:id="@+id/background">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listViewInfo"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:drawSelectorOnTop="false"
android:dividerHeight="2dp"
android:divider="#FFFFFF" /></RelativeLayout>
不加载后台的activity源代码
<RelativeLayout 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"
tools:context="nl.beachbash.beachbash.FloorPlanActivity"
android:backgroundTint="#32dd6800"
android:backgroundTintMode="src_over"
android:background="@drawable/background">
<nl.beachbash.customUI.TouchImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:nestedScrollingEnabled="false"
android:contentDescription="@string/Floorplan" /></RelativeLayout>
【问题讨论】:
-
您能否发布到目前为止的实现...您是否尝试将这些资源文件放在
drawable文件夹中? -
无论您以哪种方式挥动它,从计算和内存的角度来看,使用光栅化图像作为活动背景都会很昂贵。也就是说,它不应该在活动中“不稳定”。你是如何设置背景的?您是在使用主题属性
android:windowBackground还是将其设置为每个 Activity 中根视图的背景? -
我已经添加了布局的源代码
标签: android background