2016-03-21 93 views
0

我有一個1080x1920px圖像,我想在我的應用程序中用作背景圖像。位圖太大

在我Galaxy S6 i牛逼工作正常,但是當我去到一個較小的屏幕尺寸(S4即)我收到這樣的:

W/OpenGLRenderer﹕ Bitmap too large to be uploaded into a texture (3240x5760, max=4096x4096) 

除了不顯示在所有的形象。

這是我的佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:orientation="vertical" 
android:layout_height="match_parent" 
tools:context="${relativePackage}.${activityClass}" 
android:background="@drawable/bg"> 

<EditText android:id="@+id/username_textfield" 
      android:layout_width="270dp" 
      android:layout_height="40dp" 
      android:hint="Username" 
      android:textColorHint="#ffffff" 
      android:textColor="#ffffff" 
      android:ellipsize="start" 
      android:gravity="center_horizontal" 
      android:singleLine="true" 
      android:layout_marginTop="50dp" 
      android:layout_marginLeft="60dp" 
      android:background="@drawable/textfield_bg"/> 

<EditText android:id="@+id/password_textfield" 
      android:layout_width="270dp" 
      android:layout_height="40dp" 
      android:hint="Password" 
      android:textColorHint="#ffffff" 
      android:textColor="#ffffff" 
      android:ellipsize="start" 
      android:gravity="center_horizontal" 
      android:singleLine="true" 
      android:layout_marginTop="10dp" 
      android:layout_marginLeft="60dp" 
      android:background="@drawable/textfield_bg"/> 

我的MainActivity是除外的onCreate空。 我已閱讀關於此問題的其他帖子,但沒有人爲我提供任何真正的解決方案。

+0

的[ 「位圖太大,無法上傳到紋理」]可能的複製(http://stackoverflow.com/questions/10271020/bitmap-too-large-to-被上傳到紋理中) – Shark

+0

參見RomainGuy的[在這裏回答](http://stackoverflow.com/questions/7428996/hw-accelerated-activity-how-to-get-opengl-texture-size-limit) – Shark

+1

圖像根據設備的像素密度進行縮放。圖像實際上太大了。你可以確定OpenGL將允許的最大尺寸,並調整你的位圖的大小,以適應如果你希望它適用於所有位圖,包括那些動態添加的位圖。關於鏈接@Shark對羅曼的答案,你可能會想看看這個以及:http://stackoverflow.com/questions/26985858/gles10-glgetintegerv-returns-0-in-lollipop-only/27092070#comment59878380_27092070 – zgc7009

回答

1

如果你使用的是Android Studio中,您可以嘗試添加bg作爲圖像或矢量資源

2

您應該創建繪製的文件夾名稱nodpi。所有手機都可以使用nodpi

在res /繪製-nodpi被拉伸/是有效的任何屏幕像素密度。如果 有一個在特定密度 目錄相同的基本名稱另一個繪製,並運行你的應用程序的設備正好 有屏幕密度,密度特定的資源將被使用。 因此,-nodpi會成爲後備,用於在您的密度沒有特定內容的情況下使用。

閱讀CommonsBlog