Scale Image to fill ImageView width and keep aspect ratio

Without using any custom classes or libraries: <ImageView android:id=”@id/img” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:adjustViewBounds=”true” android:scaleType=”fitCenter” /> scaleType=”fitCenter” (default when omitted) will make it as wide as the parent allows and up/down-scale as needed keeping aspect ratio. scaleType=”centerInside” if the intrinsic width of src is smaller than parent widthwill center the image horizontally if the intrinsic width of … Read more

How to create a circular ImageView in Android? [duplicate]

I too needed a rounded ImageView, I used the below code, you can modify it accordingly: import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.widget.ImageView; public class RoundedImageView extends ImageView { public RoundedImageView(Context context) { super(context); } public … Read more

ImageView in circular through XML

This is the simplest way that I designed. Try this. dependencies implementation ‘androidx.appcompat:appcompat:1.3.0-beta01’ implementation ‘androidx.cardview:cardview:1.0.0’ <android.support.v7.widget.CardView android:layout_width=”80dp” android:layout_height=”80dp” android:elevation=”12dp” android:id=”@+id/view2″ app:cardCornerRadius=”40dp” android:layout_centerHorizontal=”true” android:innerRadius=”0dp” android:shape=”ring” android:thicknessRatio=”1.9″> <ImageView android:layout_height=”80dp” android:layout_width=”match_parent” android:id=”@+id/imageView1″ android:src=”@drawable/YOUR_IMAGE” android:layout_alignParentTop=”true” android:layout_centerHorizontal=”true”> </ImageView> </android.support.v7.widget.CardView> If you are working on android versions above lollipop <android.support.v7.widget.CardView android:layout_width=”80dp” android:layout_height=”80dp” android:elevation=”12dp” android:id=”@+id/view2″ app:cardCornerRadius=”40dp” android:layout_centerHorizontal=”true”> <ImageView android:layout_height=”80dp” android:layout_width=”match_parent” android:id=”@+id/imageView1″ android:src=”@drawable/YOUR_IMAGE” … Read more

Changing ImageView source

Changing ImageView source: Using setBackgroundResource() method: myImgView.setBackgroundResource(R.drawable.monkey); you are putting that monkey in the background. I suggest the use of setImageResource() method: myImgView.setImageResource(R.drawable.monkey); or with setImageDrawable() method: myImgView.setImageDrawable(getResources().getDrawable(R.drawable.monkey)); *** With new android API 22 getResources().getDrawable() is now deprecated. This is an example how to use now: myImgView.setImageDrawable(getResources().getDrawable(R.drawable.monkey, getApplicationContext().getTheme())); and how to validate for old API … Read more

Border for an Image view in Android?

I set the below xml to the background of the Image View as Drawable. It works. <?xml version=”1.0″ encoding=”UTF-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android”> <solid android:color=”#FFFFFF” /> <stroke android:width=”1dp” android:color=”#000000″ /> <padding android:left=”1dp” android:top=”1dp” android:right=”1dp” android:bottom=”1dp” /> </shape> And then add android:background=”@drawable/yourXmlFileName” to your ImageView

How to set tint for an image view programmatically in android?

UPDATE: @ADev has newer solution in his answer here, but his solution requires newer support library – 25.4.0 or above. You can change the tint, quite easily in code via: imageView.setColorFilter(Color.argb(255, 255, 255, 255)); // White Tint If you want color tint then imageView.setColorFilter(ContextCompat.getColor(context, R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode.MULTIPLY); For Vector Drawable imageView.setColorFilter(ContextCompat.getColor(context, R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode.SRC_IN);

How to load an ImageView by URL in Android? [closed]

From Android developer: // show The Image in a ImageView new DownloadImageTask((ImageView) findViewById(R.id.imageView1)) .execute(“http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png”); public void onClick(View v) { startActivity(new Intent(this, IndexActivity.class)); finish(); } private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { ImageView bmImage; public DownloadImageTask(ImageView bmImage) { this.bmImage = bmImage; } protected Bitmap doInBackground(String… urls) { String urldisplay = urls[0]; Bitmap mIcon11 = null; … Read more

How to make an ImageView with rounded corners?

This is pretty late in response, but for anyone else that is looking for this, you can do the following code to manually round the corners of your images. http://www.ruibm.com/?p=184 This isn’t my code, but I’ve used it and it’s works wonderfully. I used it as a helper within an ImageHelper class and extended it … Read more