2011-05-04 47 views
3

我做:爲什麼是我進口PNG等低質量的

android:background="@drawable/mobile_vforum_bg" 
在main.xml中的文件

到剛剛設置的BG。

它的工作原理,只是在模擬器上查看圖像的質量非常差。它的PNG爲320x480(96dpi,在低,中,高文件夾中相同)。當我使用鈦來構建我的android應用程序時,它看起來很好。我現在使用eclipse和java,它看起來很糟糕。

回答

10

我在將高分辨率圖像設置爲活動背景時遇到此問題,並且我可以使用活動的onCreate()方法中的以下java代碼來解決此問題。

 BitmapFactory.Options myOptions = new BitmapFactory.Options(); 
     myOptions.inDither = true; 
     myOptions.inScaled = false; 
     myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; 
     myOptions.inDither = false; 
     myOptions.inPurgeable = true; 
     Bitmap preparedBitmap = BitmapFactory.decodeResource(yourAppName.getSharedApplication().getResources(), 
       R.drawable.yourImage, myOptions); 
     Drawable background = new BitmapDrawable(preparedBitmap); 
     ((LinearLayout) findViewById(R.id.yourLayoutId)) 
      .setBackgroundDrawable(background); 

如果您使用此代碼,也不要從佈局xml設置背景。如果這不起作用,請嘗試在AndroidManifest.xml中的應用程序標籤外設置以下行:

<supports-screens android:largeScreens="true" 
    android:normalScreens="true" android:smallScreens="true" 
    android:anyDensity="true" /> 

希望這有助於!

8

嘗試將其移動到「res/drawable_hdpi」文件夾中,該文件夾適用於我。

+0

我在所有三個文件夾中都有相同的圖像。也許我正在測試的模擬器被設置爲低dpi或者其他東西 – Ronnie 2011-05-04 20:41:06

+0

SDK優化了所有圖像,所以我認爲還有另外一個選項 - 把它放到/ res/raw文件夾中(你在那裏放置的文件在構建過程中保持不變)並加載它手動使用[Resources.openRawResource()](http://developer.android.com/reference/android/content/res/Resources.html#openRawResource(int))。 – Grishka 2011-05-04 20:55:14

+0

我不能在XML中進行這個調用,但就像我在上面做的那樣。那麼我將如何使用java設置應用程序的背景呢? – Ronnie 2011-05-04 21:55:12