I know this question has been asked many times before, but all the answers aren't helping me or seem to contradict each other.
- This one suggests I need to programmatically set the width of the ImageView.
- This one and this one suggest doing it by overriding the
onMeasure()
method on ImageView in a subclass. - This one suggests it can be done with just a quick code snippet:
.
ImageView imageView=new ImageView(context);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(bitmap);
imageView.setMaxHeight(maxHeight);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
layout.addView(imageView);
Thought I've tried this (I'm new to Android, sorry) and it didn't seem to work for me. My goal is to programmatically construct the following:
<horizontal layout>
<container width_weight=X>
<image A fills parent width/>
</container>
<container width_weight=Y>
<image B fills parent width/>
</container>
<container width_weight=Z>
<image C fills parent width/>
</container>
</horizontal layout>
where X, Y, and Z are different positive integers. Can someone please help me make sense of all this information?