简体   繁体   中英

Android device is not showing the background image

I have created a project, targeting android 4.4 - API Level 19 , as suggested by 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.

Here is my 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 ?

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.

Try with a lower-resolution background. The one you are trying might be too big. You can check that in your logcat.

In your logcat you will see a message like this:

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.

you may need to add this to your manifest file . 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">

尝试删除那些赋予可绘制名称的下划线。

Need to check drawable size.Add the image in four resolutions.

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

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

Decrease Height And Width of the Image . This will solve problem . You can see image too large error generated by logcat also

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

You can also try to disable hardware acceleration to the view you are setting background

myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)

and then set the background

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM