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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With