mdpi image is too small for 10" android tablet

后端 未结 4 1902
我在风中等你
我在风中等你 2020-12-24 07:54

I have drawables for each density as ldpi,mdpi,hdpi and xhdpi.

Problem: Both 10\" tablet device (1280x800) and a handset device 320x480 uses medium density

相关标签:
4条回答
  • 2020-12-24 08:23

    I include some resources in drawable-xlarge, and drawable-large folders, in addition to the drawable-hdpi folders. This works for me.

    Another alternative, is to scale an image in code directly, which I do with the following code:

    Drawable scaledIcon = new BitmapDrawable(Bitmap.createScaledBitmap(myImage, pxInt, pxInt, true));
    myImageView.setBackgroundDrawable(scaledIcon);
    

    It is not a good idea to scale a lot of images in your code (using this method), as I think it is resource intensive to modify the images on the fly like this. I do use this in some cases, where the image I am using may not be a standard size (and I want it to fit right always).

    0 讨论(0)
  • 2020-12-24 08:25

    These are defined as common practice:

    Devices:

    drawable-ldpi/xyz.png          low resolution devices 320x240 (now a days no phone comes with this resolution)
    drawable-mdpi/xyz.png          medium resolution devices 480x320
    drawable-hdpi/xyz.png          high resolution devices 800x480
    drawable-xhdpi/xyz.png         Extra high resolution devices 1280*720
    drawable-xxhdpi/xyz.png        Extra Extra high resolution devices 1920x1080
    

    Tablets:

    drawable-large-mdpi/xyz.png    7” Tablet (600x1024 mdpi)
    drawable-xlarge-mdpi/xyz.png   10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
    
    0 讨论(0)
  • 2020-12-24 08:39

    If you want to achieve this without increasing your app size, there is a way to let a high density screen and a large medium density screen use the same resource. You need to place the image you want to re-use in the 'drawable-nodpi' folder. This will stop the platform performing its own scaling when using it. For example, assuming you have a resource called 'my_resource', if you want the tablet-size screen to use your xhdpi resource, then move it out of drawable-xhdpi and rename it like this:

    /drawable-nodpi/my_resource_xhdpi.png
    

    Then in both the drawable-xhdpi and drawable-xlarge folders, create a file called my_resource.xml which looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/my_resource_xhdpi">
    </bitmap>
    

    Now when you use @drawable/my_resource, the xhdpi version will be used by xhdpi screens and xlarge screens, and you only have to maintain one version of the image. I use this technique quite a lot and it works really well. Hope that helps!

    0 讨论(0)
  • 2020-12-24 08:40

    You should add a second identifier large and/or xlarge to your drawable folders. Increase the size in drawable-xlarge-mdpi until you are happy with the result while the drawable-mdpi will be the same size as before.

    This increases the app size, but it will fix your issue.

    0 讨论(0)
提交回复
热议问题