Android设备未显示背景图片

时间:2014-03-16 07:13:05

标签: java android android-activity

我已根据eclipse的建议创建了一个定位android 4.4 - API Level 19的项目。

无论如何,在模拟器上一切看起来都很完美 - 这是截图:

app screenshot

当我在真实设备上安装它时出现问题 - 运行android 4.1.2。除了背景图片外,一切都很完美,像魅力一样。它显示的是白色背景,就像图片不存在一样。

这是我的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>

android:background="@drawable/wg_blurred_backgrounds_12不是4.1.2吗?

我是否必须更改预设中的任何内容?这就是我现在所拥有的:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

我知道我错过了一些非常小的东西,但我不能把它当成初学者。

9 个答案:

答案 0 :(得分:30)

尝试使用较低分辨率的背景。你正在尝试的那个可能太大了。你可以在你的logcat中检查它。

答案 1 :(得分:15)

在您的logcat中,您将看到如下消息:

Bitmap too large to be uploaded into a texture (2496x4437, max=4096x4096)

最大值为4096x4096,这是设备上运行的OpenGL版本的值GL_MAX_TEXTURE_SIZE

答案 2 :(得分:4)

您可能需要将其添加到清单文件中。 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">

答案 3 :(得分:0)

尝试删除给予drawable名称的下划线。

答案 4 :(得分:0)

需要检查可绘制的尺寸。以四种分辨率添加图像。

http://developer.android.com/guide/practices/screens_support.html

答案 5 :(得分:0)

将图像保存在每个可绘制文件夹中,如xhdpi,xxhdpi,xxxhdpi中的分辨率。

答案 6 :(得分:0)

降低图像的高度和宽度。这将解决问题。你可以看到logcat产生的图像太大错误

答案 7 :(得分:0)

确保在可绘制文件中没有在图像文件旁边显示(24)(v 24),重新复制图像并将其保存为没有{{ 1}},因为它将准备用于(24)及更高版本,所以我的手机会使用它,这就是我部分API 24失败的原因。

答案 8 :(得分:0)

您还可以尝试将硬件加速禁用为您要设置背景的视图

myView.setLayerType(View.LAYER_TYPE_SOFTWARE,空)

然后设置背景