Fix ImageView’s size with dp
or fill_parent
and set android:scaleType
to fitXY
.
In your case you need to
- Fix the ImageView’s size.
You need to use dp unit so that it will look the same in all devices. - Set
android:scaleType
tofitXY
Below is an example:
<ImageView
android:id="@+id/photo"
android:layout_width="200dp"
android:layout_height="100dp"
android:src="https://codeutility.org/@drawable/iclauncher"
android:scaleType="fitXY"/>
For more information regarding ImageView scaleType please refer to the developer website.
Try this
ImageView img
Bitmap bmp;
int width=100;
int height=100;
img=(ImageView)findViewById(R.id.imgView);
bmp=BitmapFactory.decodeResource(getResources(),R.drawable.image);//image is your image
bmp=Bitmap.createScaledBitmap(bmp, width,height, true);
img.setImageBitmap(bmp);
Or
If you want to load complete image size in memory then you can use
<ImageView
android:id="@+id/img"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="https://codeutility.org/@drawable/image"
android:scaleType="fitXY"/>