androidimageviewdensity-independent-pixel

android Imageview layoutparams in dip?


I'm using the following code :

ImageView i = new ImageView(mContext);

i.setImageResource(mImageIds[position]);

i.setScaleType(ImageView.ScaleType.FIT_XY);

       //pixels settings !!!

i.setLayoutParams(new Gallery.LayoutParams(200, 100));

but as you can see, it is setting the layout dimensions in pixels.

Does anybody know how to do the same thing but in "dip" ?


Solution

  • See http://developer.android.com/guide/practices/screens_support.html#screen-independence

    On how to convert from dpi to pixels.