Ruwan Dissanayaka
Ruwan Dissanayaka

Reputation: 315

Change the size of an Imageview in android

I set the default size of an imageview as width=511 and height=385 . Source of the imageview is from drawable. Based on a dynamic value I need to change the size of the image view or the image fit in to it. For example I want to change the size of the imageview or image inside it to width=140 and height=100

ImageView scale=(ImageView) findViewById(R.id.scaleimage);

Upvotes: 5

Views: 7733

Answers (1)

Booger
Booger

Reputation: 18725

If you set the width and height attributes of your ImageView to specific values, the system will automatically scale you images to fit.

Unless I don't understand your question, I think it is as simple as:

<ImageView
    android:layout_width="140dp"
    android:layout_height="100dp"
    android:scale_type="fitXY"
/>

To set this in code, try:

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(140,100);
yourView.setLayoutParams(layoutParams);

Upvotes: 9

Related Questions