Android ImageView adjusting parent’s height and fitting width

Thanks to @Julien and @js. Here is complete solution of ImageView that will stretch bitmap height preserving aspect ratio even if bitmap is smaller than ImageView. public class ResizableImageView extends ImageView { public ResizableImageView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ Drawable d = getDrawable(); if(d!=null){ // ceil … Read more

How to add a shadow and a border on circular imageView android?

I modified the CircularImageView found here to achieve what you want. To create a shadow around the border, I simply used these two lines: this.setLayerType(LAYER_TYPE_SOFTWARE, paintBorder); paintBorder.setShadowLayer(4.0f, 0.0f, 2.0f, Color.BLACK); You need setLayerType due to hardware acceleration on HoneyComb and up. It didn’t work without it when I tried it. Here is the full code: … Read more

How to set VectorDrawable as an image for ImageView programmatically

If you want to use vector drawables (less OR greater than API 21) just do the following: Set the image programmatically (e.g. in your activity): imageView.setImageResource(R.drawable.ic_left_arrow_blue); or by XML: app:srcCompat=”@drawable/your_vector_name” In your app’s build.gradle you need to include: android { defaultConfig { vectorDrawables.useSupportLibrary = true } } And for vector support for less then API … Read more

Make ImageView fit width of CardView

You need to do 2 things : 1) Call setPreventCornerOverlap(false) on your CardView. 2) Put rounded Imageview inside CardView About rounding your imageview, I had the same problem so I made a library that you can set different radii on each corners. There is one good library(vinc3m1’s RoundedImageView) that supports rounded corners on ImageView, but … Read more