Set size of ImageView in px at runtime

前端 未结 2 1687
星月不相逢
星月不相逢 2021-01-16 22:55

I want to put 8 image thumbs in one horizontal line, using the whole available width.
The images are retrieved from a webservice which lets me specify the dimensions.

相关标签:
2条回答
  • 2021-01-16 23:17

    I'd suggest using this:

    widthPx = getWindowManager().getDefaultDisplay().getWidth();
    
    0 讨论(0)
  • 2021-01-16 23:30

    Add the ImageViews with a fixed size, i.e.:

    thumbs.addView (iv, new LayoutParams(thumbSize, thumbSize));
    

    To answer (partially) the questions in the comments:

    The ImageView API says:

    takes care of computing its measurement from the image so that it can be used in any layout manager

    so it is probably assuming 60px for a 160 dpi (I may be wrong there).

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