Why is my imported PNG such low quality

2020-02-29 02:50发布

问题:

I am doing:

android:background="@drawable/mobile_vforum_bg"

in the main.xml file to just set the BG.

It works, just the quality of the image is very poor when viewed on the emulator. Its a PNG at 320x480 (96dpi and the same in the low, med and high folder). When I was using Titanium to build my android app, it looked fine. I am now using eclipse and java and it looks bad.

回答1:

I had this issue while setting a high resolution image as an activity's background and I was able to solve it by using the following java code from the Activity's onCreate() method.

        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);

Also don't set the background from the layout xml if you are using this code. In case this doesn't work try setting the following lines outside the application tag in AndroidManifest.xml

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

Hope this Helps!!!



回答2:

Try to move it to the "res/drawable_hdpi" folder, that worked for me.