Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

android - imageview height as the wrap_content of the shown image

I want the width of an ImageView to be set by the parent and the height should be aspect proportional. The reasons for this is that next is shown a TextView that I want to place just under the ImageView.

I can get image to show correctly using

android:layout_width="fill_parent"
android:layout_height="fill_parent"

however the ImageView height become the parent height which is much larger than that of the shown stretched image. One idea was to make parent smaller vertically, but.. there I don't yet know the stretched image size.

The following doesn't work because a small image is not filled up horizontally.

android:layout_width="fill_parent"
android:layout_height="wrap_content"

Messing around with

android:layout_height="wrap_content"

for the RelativeLayout surrounding it all does not help. Also tried FrameLayout and LinearLayout and failed.

Any ideas?

question from:https://stackoverflow.com/questions/19665205/imageview-height-as-the-wrap-content-of-the-shown-image

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to set adjustViewBounds to true.

imageView.setAdjustViewBounds(true);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...