Skip to content Skip to sidebar Skip to footer

Bitmap Size Appears Different In Different Android Device

Hello I am trying to set the image in the ImageView but after setting the image it is appearing different in size on different android device. Sony Z Experia 4.3 Samsung Y Dous 2.

Solution 1:

In android you have the option hdpi, mdpi, xdpi,etc..

folders for that , you have to create different images according your device resolution and put your images at there after confirming your device resolution and density category.

for the more reference why it'll happen you can see here

here i explain some chart may be helpful to you.

Low density Small screens QVGA 240x320 (120dpi):

layout-small-ldpi (240x320)  
layout-small-land-ldpi (320x240)

Low density Normal screens WVGA400 240x400 (x432) (120dpi):

layout-ldpi  (240 x 400 )
layout-land-ldpi  (400 x 240 )

Medium density Normal screens HVGA 320x480 (160dpi):

layout-mdpi (320 x 480 )
layout-land-mdpi (480 x 320 )

Medium density Large screens HVGA 320x480 (160dpi):

layout-large-mdpi (320 x 480 )
layout-large-land-mdpi (480 x 320)

Galaxy Tab ( 240 dpi ):

layout-large  (600 x 1024) 
layout-large-land  (1024 x 600)

High density Normal screens WVGA800 480x800 (x854) (240 dpi):

layout-hdpi (480 x 800)
layout-land-hdpi (800 x 480)

Xoom (medium density large but 1280x800 res) (160 dpi):

layout-xlarge (800 x 1280)
layout-xlarge-land (1280 x 800)

Solution 2:

There are two ways you need to go about this.

  1. As mentioned is you need to have images of various sizes to account for different Android devices having different display densities. There are several densities outlined here: http://developer.android.com/guide/practices/screens_support.html
  2. Now that you have images of different sizes, you may also want to go an extra step and scale them perfectly to a specific width and height. Try the following layout (note that dip is the same as dp)

<ImageView
    android:id="@+id/logo"
    android:layout_width="200dp"
    android:layout_height="75dp"
    android:padding="5dip"
    android:scaleType="fitStart" />

Of course you could just use a single image (ignore #1) and use #2 to stretch it to the appropriate size, but then you might be scaling an image 10x bigger, and it will look very stretched.

Solution 3:

you need different images for different densities devices. Sony Z has higher density thats why its look smaller.xxdpi,xdpi,hdpi, mdpi and ldpi folders are used for this thing. Try this tool to convert images for different devices. I know this tool is for icon only. its generate icons for different densities. but you can give it a try.

Solution 4:

Try this code and provide height and width in percentage of your screen

Displaydisplay= getWindowManager().getDefaultDisplay();
DisplayMetricsmetrics=newDisplayMetrics();

display.getMetrics(metrics);

intwidthScreen= metrics.widthPixels;
intheightScreen= metrics.heightPixels;

ImageView logo=findviewById(R.id.logo);

logo.getLayoutParams().height = (int) (heightScreen * 0.10);//it set the height of image 10% of your screen
logo.getLayoutParams().width = (int) (widthScreen * 0.10);

Post a Comment for "Bitmap Size Appears Different In Different Android Device"