Java Android 设备未显示背景图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22434070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android device is not showing the background image
提问by chility
I have created a project, targeting android 4.4 - API Level 19
, as suggested by eclipse.
我创建了一个项目,目标android 4.4 - API Level 19
是 eclipse 所建议的。
Anyways, on the emulator everything looks perfect - here is a screenshot:
无论如何,在模拟器上一切看起来都很完美 - 这是一个截图:
The problems comes when I install it on my real device - running android 4.1.2
. Everything is just perfect and working like a charm, excepting the background image. It is showing a white background, like the picture does not exists.
当我将它安装在运行 android 的真实设备上时,问题就出现了4.1.2
。除了背景图像外,一切都非常完美,并且像魅力一样工作。它显示白色背景,就像图片不存在一样。
Here is my xml:
这是我的 xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical"
android:gravity="center"
android:padding="30dp"
android:background="@drawable/wg_blurred_backgrounds_12"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnTopJokes"
android:onClick="showTopJokes"
android:gravity="center"
/>
<Button
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnNewJokes"
android:onClick="showNewJokes"
android:gravity="center"
/>
<Button
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnAllJokes"
android:onClick="showAllJokes"
android:gravity="center"
/>
<Button
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnMyFavorites"
android:onClick="showFavorites"
android:gravity="center"
/>
<Button
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnCategories"
android:onClick="showCategories"
android:gravity="center"
/>
<Button
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnAddNewJoke"
android:gravity="center"
/>
</LinearLayout>
Isn't android:background="@drawable/wg_blurred_backgrounds_12
working on android 4.1.2
?
不是android:background="@drawable/wg_blurred_backgrounds_12
在安卓上工作4.1.2
吗?
Do I have to change anything in the premissions? Here is what I have now:
我是否必须更改前提中的任何内容?这是我现在所拥有的:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
I know that I miss something really small, but I'm not able to spot it as a beginner.
我知道我错过了一些非常小的东西,但作为初学者,我无法发现它。
采纳答案by thekoreanbeaver
Try with a lower-resolution background. The one you are trying might be too big. You can check that in your logcat.
尝试使用较低分辨率的背景。您正在尝试的那个可能太大了。您可以在 logcat 中检查。
回答by CodeWalker
Try removing those underscores given to the name of the drawable.
尝试删除那些赋予可绘制名称的下划线。
回答by Max Worg
In your logcat you will see a message like this:
在您的 logcat 中,您将看到如下消息:
Bitmap too large to be uploaded into a texture (2496x4437, max=4096x4096)
Bitmap too large to be uploaded into a texture (2496x4437, max=4096x4096)
The max is 4096x4096
which is the value GL_MAX_TEXTURE_SIZE
for the version of OpenGL that is running on the device.
最大值是设备上运行的 OpenGL 版本4096x4096
的值GL_MAX_TEXTURE_SIZE
。
回答by Ramesh sambu
Need to check drawable size.Add the image in four resolutions.
需要检查可绘制大小。以四种分辨率添加图像。
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/guide/practices/screens_support.html
回答by Ruchit Sawalkar
Save the image in every folder of drawable like in xhdpi,xxhdpi,xxxhdpi with respect to thier resolution.
将图像保存在可绘制的每个文件夹中,例如 xhdpi、xxhdpi、xxxhdpi 中的分辨率。
回答by Usman Iqbal
Decrease Height And Width of the Image . This will solve problem . You can see image too large error generated by logcat also
减少图像的高度和宽度。这将解决问题。您还可以看到 logcat 生成的图像太大错误
回答by Adam moufid
you may need to add this to your manifest file . android:hardwareAccelerated="false" , android:largeHeap="true"
您可能需要将此添加到您的清单文件中。android:hardwareAccelerated="false" , android:largeHeap="true"
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/logo"
android:supportsRtl="true"
android:hardwareAccelerated="false"
android:largeHeap="true"
android:theme="@style/AppTheme">
回答by Kream
Make sure it doesn't say (24)
or (v 24)
next to the image file you have in your drawable file, re-copy the image and make it save it as the type with no (24)
in it as it will prepare it to be used for API 24
and above, my phone uses that's why it failed on my part API 23
.
确保它没有说(24)
或(v 24)
在您的可绘制文件中的图像文件旁边,重新复制图像并将其保存为没有类型的类型,(24)
因为它将准备好用于API 24
及以上,我的手机使用这就是我失败的原因API 23
。