簡體   English   中英

Android 設備未顯示背景圖像

[英]Android device is not showing the background image

我創建了一個項目,針對android 4.4 - API Level 19 ,正如 eclipse 所建議的那樣。

無論如何,在模擬器上一切看起來都很完美 - 這是一個截圖:

應用截圖

當我將它安裝在運行 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在 android 4.1.2上工作嗎?

我是否必須更改前提中的任何內容? 這是我現在所擁有的:

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

我知道我錯過了一些非常小的東西,但作為初學者,我無法發現它。

嘗試使用較低分辨率的背景。 您正在嘗試的那個可能太大了。 您可以在 logcat 中檢查。

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

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

最大值為4096x4096 ,這是設備上運行的 OpenGL 版本的GL_MAX_TEXTURE_SIZE值。

您可能需要將此添加到您的清單文件中。 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">

嘗試刪除那些賦予可繪制名稱的下划線。

需要檢查可繪制大小。以四種分辨率添加圖像。

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

將圖像保存在可繪制的每個文件夾中,例如 xhdpi、xxhdpi、xxxhdpi 中的分辨率。

減少圖像的高度和寬度。 這將解決問題。 您還可以看到 logcat 生成的圖像太大錯誤

確保它沒有在可繪制文件中的圖像文件旁邊顯示(24)(v 24) ,重新復制圖像並將其保存為沒有(24)的類型,因為它會准備它用於API 24及更高版本,我的手機使用這就是它在我的部分API 23上失敗的原因。

您也可以嘗試禁用硬件加速到您正在設置背景的視圖

myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)

然后設置背景

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM