Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android imageview wrap_content

Hello everyone and thanks for your help.

I have a project in Android Studio.

I am using an ImageView inside vertical LinearLayout.

Here are my parameters;

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/imageView2"
    android:src="@drawable/myimg"
/>

You can see my image down below (red block) and imageview borders (blue line) there is no problem with width, it is %100 of my layout, but I want my image to fit the area while keeping the aspect ratio. as you can see in image there are white spaces, the ImageView height is bigger than my image, how can I fit image in ImageView?

I want this because I want that image to fit the width even the phone is portrait or landscape.

enter image description here

like image 208
yucel Avatar asked Sep 23 '14 12:09

yucel


People also ask

What is ImageView in android?

Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.

How do I check image size on android?

On android go to photos, select your photo and click the ... in the top right. Scroll to bottom of page to find image size.

How do you change the size of a picture on android?

Tap the image you want to adjust. You can adjust the size of an image or rotate it: Resize: Touch and drag the squares along the edges. Rotate: Touch and drag the circle attached to the image.

How can I find the aspect ratio of an image in android?

float aspect_ratio = (float)originalWidth / (float)originalHeight ; Because this typecasting operation will return a float value.


1 Answers

I found the solution android:adjustViewBounds="true"

like image 185
yucel Avatar answered Oct 15 '22 03:10

yucel