Khaled Saifullah
Khaled Saifullah

Reputation: 2289

ImageView resize dynamically acccording to the image size in android

How can I resize ImageView dynamically according to the height and width of an image in android ?

Upvotes: 1

Views: 1734

Answers (2)

Andre Perkins
Andre Perkins

Reputation: 7800

Set android:adjustViewBounds="true" in your ImageView. You can read more about it here.

ThereFore, your imageview xml will be something like:

<ImageView
    android:id="@+id/iv_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:src="@drawable/image"" />

Upvotes: 3

MilapTank
MilapTank

Reputation: 10076

ImageView have property wrap_content

via XML

 <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/your_image"" />

via JAVA code

ImageView imageView = new ImageView(this);
imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
imageView.setImageResource(R.drawable.your_image);

Upvotes: 0

Related Questions