Scaling ImageView to device width

前端 未结 9 851
清酒与你
清酒与你 2020-12-05 00:54

In my Android App I have a Activity which show images which have following size 244 x 330. I want to show those images in full device width.

My layout f

相关标签:
9条回答
  • 2020-12-05 01:53

    Have you tried setting it programmatically via ImageView.setScaleType()?

    setAdjustViewBounds( false ) might help as well.

    Edit: sorry, I mis-read the question. Regardless, setAdjustViewBounds() still might help. Never used it though.

    0 讨论(0)
  • 2020-12-05 01:54

    One of the ways to do it is by setting android:adjustViewBounds="true" to the ImageView and set the scale type to "fitCenter" in the xml file. This should work as expected. You can also do this programatically by setting ImageView.adjustViewBounds(true) and ImageView.setScaleType(ScaleType.FIT_CENTER).

    0 讨论(0)
  • 2020-12-05 01:56

    I don't see the images anymore and the question is old but just in case someone else finds this and has the same problem. Wouldn't it be better to just get float screenWidth = getResources().getDisplayMetrics().widthPixels and set the ImageView LayoutParamters programmatically to scale the image to screenWidth. Just an idea !!

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