Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 886
Ruwan Dissanayaka Avatar asked Nov 04 '12 14:11

Ruwan Dissanayaka


1 Answers

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);
like image 192
Booger Avatar answered Oct 20 '22 17:10

Booger