androidandroid-layoutbitmapandroid-resolution

Bitmap size difference for devices with same density, inches and resolution


I have two tablet devices:

1) Asus Memo Pad 172V tablet

Specs given online as: 600 * 1024 pixels, 7.0 inches (~170 ppi pixel density) LINK

Specs through code: 1024 * 552 pixels, 7.0 inches (160 ppi pixel density)

2) MID 7510 tablet

Specs given online as: 800 * 480 pixels, 7.0 inches (no density mentioned anywhere) LINK

Specs through code: 1024 * 552 pixels, 7.0 inches (160 ppi pixel density)

My problem is:

- Both the tablets have the same density and resolutions (by code), so how can I distinguish between them in order to set the bitmap height (width is coming correct for both) as in case of MID7510, the bitmap height is extended slight down.

- Is there any other factors that are responsible for causing different bitmap sizes for both
tablets ?

- Why are specs coming different by code and are given different online ?

Code to get density and resolution:

 DisplayMetrics dm = new DisplayMetrics();
 getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);                       

    int screenWidth = dm.widthPixels;
    int screenHeight = dm.heightPixels;                     

    // Display device dpi (density) value in pixels
    int screenDPIy = (int)dm.ydpi;

Solution

  • The chart was on drawable-hdpi folder.

    I was doing simply this:

    img.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    

    The height was not proper in MID 7510 doing so.

    Setting height like this worked for both the tablets:

    static int imgHeight = 0;
    
    Drawable d = (BitmapDrawable) getResources().getDrawable(R.drawable.chart);
    
    imgHeight = d.getIntrinsicHeight(); 
    
    final ImageView img = new ImageView(getActivity());
    
    img.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) (imgHeight * 1.5)));
    

    This is because 1 hdpi= 1.5 mdpi. So total height should be 1.5 times of image height.