Android ImageView that supports different radii on each corner.

Overview

SelectableRoundedImageView

Android Arsenal

Note that this project is no longer maintained.

Android ImageView that supports different radii on each corner. It also supports oval(and circle) shape and border. This would be especially useful for being used inside CardView which should be rounded only top left and top right corners(Don't forget to call setPreventCornerOverlap(false) on your cardview).

I referred to the RoundedImageView, developed by Vince, in developing this new one, and I really appreciate him. Also, I wrote a short article about how I made this library and my thoughts on CardView, check my blog post.

Get the sample app on Play Store.
Play Store Image

SelectableRoundedImageView Sample Screenshots

Note: When using with Glide, be sure to add asBitmap() chain, like below.

Glide.with(context)
    .load(src)
    .asBitmap()
    .listener(l)
    .into(imageView) 

Note: When using with Android-Universal-Image-Loader, be sure to use SimpleBitmapDisplayer or FadeInBitmapDisplayer rather than RoundedBitmapDisplayer(or RoundedVignetteBitmapDisplayer) when building DisplayImageOptions. See below code.

options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.ic_stub)
                .showImageForEmptyUri(R.drawable.ic_empty)
                .showImageOnFail(R.drawable.ic_error)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
//              .displayer(new RoundedBitmapDisplayer(20))
//              DO NOT USE RoundedBitmapDisplayer. Use SimpleBitmapDisplayer!
                .displayer(new SimpleBitmapDisplayer())
                .build();

Usage

Define in xml:

<com.joooonho.SelectableRoundedImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/image"
        android:src="@drawable/photo1"
        android:scaleType="centerCrop"
        app:sriv_left_top_corner_radius="16dip"
        app:sriv_right_top_corner_radius="0dip"
        app:sriv_left_bottom_corner_radius="48dip"
        app:sriv_right_bottom_corner_radius="16dip"
        app:sriv_border_width="2dip"
        app:sriv_border_color="#008fea"
        app:sriv_oval="true" />

Or in code:

SelectableRoundedImageView sriv = new SelectableRoundedImageView(context);
sriv.setScaleType(ScaleType.CENTER_CROP);
sriv.setCornerRadiiDP(4, 4, 0, 0);
sriv.setBorderWidthDP(4);
sriv.setBorderColor(Color.BLUE);
sriv.setImageDrawable(drawable);
sriv.setOval(true);

Including In Your Project

If you are using Android Studio, SelectableRoundedImageView is available through Gradle.

dependencies {
    compile 'com.joooonho:selectableroundedimageview:1.0.1'
}

Also SelectableRoundedImageView is presented as a library project. You can include this project by referencing it as a library project in Eclipse or ant(A standalone JAR is not possible due to the custom attributes).

Developed By

License

Copyright 2014 Joonho Kim

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • giving error while pulling image using glide

    giving error while pulling image using glide

    Glide.with(getContext())
                    .load(imageUri))
                    .placeholder(R.drawable.abc)
                    .into(imageView);
    

    java.lang.ClassCastException: android.graphics.drawable.TransitionDrawable cannot be cast to com.joooonho.SelectableRoundedImageView$SelectableRoundedCornerDrawable

    opened by ghost 9
  • Issue with UIL place holder

    Issue with UIL place holder

    I have a problem with Universal Image Loader's image place holder, when i set a drawable (a shape with solid color) as image place holder and imageview's backgroud is transparent or white, its look like in image. Please fix!

    roundimageview_err

    opened by boojtran 6
  • The image cannot be showed sometimes when used by Glide 3.7.0

    The image cannot be showed sometimes when used by Glide 3.7.0

    SimpleTarget target = new SimpleTarget<GlideBitmapDrawable>() {
                @Override
                public void onResourceReady(GlideBitmapDrawable resource, GlideAnimation glideAnimation) {
    
                    selectRoundIv.setImageBitmap(resource.getBitmap());
                }
            };
    
    Glide.with(context).load(path).into(target);
    

    This is my code for loading url image. The "selectRoundIv" is the object of SelectableRoundedImageView. It seems worked. But when I set scaleType with centerCrop, there's a problem. The image cannot be showed, or be showed without corners.

    qq 20160908113755

    This is the effect of this issue. By the way, the top imageview' url and the top selectableRoundImageView's url are the same.

    qq 20160908114828 And this is the effect which is image be showed without cornors.

    opened by mikiller 4
  • java.lang.OutOfMemoryError

    java.lang.OutOfMemoryError

    SelectableRoundedImageView$SelectableRoundedCornerDrawable.drawableToBitmap(SelectableRoundedImageView.java:387) SelectableRoundedImageView$SelectableRoundedCornerDrawable.fromDrawable(SelectableRoundedImageView.java:364) SelectableRoundedImageView.setImageDrawable(SelectableRoundedImageView.java:145)

    opened by Daewooo 2
  • 在ListView中ImageView会根据当前Item的高度而改变图片的显示高度。

    在ListView中ImageView会根据当前Item的高度而改变图片的显示高度。

    在ListView里面,我使用的图片加载工具是 novoda-image-loader 但是我更希望SelectableRoundedImageView做一些修改,因为使用Aquery加载图片也会有相同的问题。

    public class GridAdapter extends BaseAdapter {
        private List<NaiFen> data;
        private Context c;
    
        public GridAdapter(Context c, List<NaiFen> dataList) {
            this.c = c;
            this.data = dataList;
        }
    
        @Override
        public int getCount() {
            return 20;
        }
    
        @Override
        public Object getItem(int arg0) {
            return null;
        }
    
        @Override
        public long getItemId(int arg0) {
            return 0;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (null == convertView) {
                holder = new ViewHolder();
                convertView = LayoutInflater.from(c).inflate(
                        R.layout.grid_item_layout, null);
                holder.img = (SelectableRoundedImageView) convertView.findViewById(R.id.img);
                holder.title_tv = (TextView) convertView
                        .findViewById(R.id.title_tv);
                holder.price_tv = (TextView) convertView
                        .findViewById(R.id.price_tv);
                holder.flag_img = (ImageView) convertView
                        .findViewById(R.id.flag_img);
                holder.old_price_tv = (TextView) convertView
                        .findViewById(R.id.old_price_tv);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.old_price_tv.getPaint()
                    .setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                        loadBigImage(item.getPic_url(), holder.img);
            return convertView;
        }
    
        static class ViewHolder {
            SelectableRoundedImageView img;
            TextView title_tv;
            ImageView flag_img;
            TextView price_tv;
            TextView old_price_tv;
        }
    
        protected void loadBigImage(String url, ImageView view) {
                view.setTag(imageBigTagFactory.build(url, c));
                imageBigManager.getLoader().load(view);
        }
    }
    
    opened by Vurtex 2
  • When I set SelectableRoundedImageView ,outside CardView cardCornerRadius can't working

    When I set SelectableRoundedImageView ,outside CardView cardCornerRadius can't working

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/news_card_view" android:layout_width="match_parent" android:layout_height="68dp" app:cardBackgroundColor="#3f3f3f" app:cardCornerRadius="8dp" app:contentPadding ="0dp" app:cardPreventCornerOverlap="false"> <com.joooonho.SelectableRoundedImageView app:sriv_left_top_corner_radius="8dp" app:sriv_right_top_corner_radius="0dip" app:sriv_left_bottom_corner_radius="8dp" app:sriv_right_bottom_corner_radius="0dp" android:background="@drawable/news_image_bg" android:id="@+id/pic" android:layout_width="68dp" android:layout_height="68dp" android:layout_marginRight="@dimen/default_padding" android:scaleType="centerCrop" /> </android.support.v7.widget.CardView>


    when i do like this ,cardview's shape is rectangle

    opened by kHRYSTAL 1
  • with Glide transition not work

    with Glide transition not work

    if crashing

    Glide.with(context) .load(POST_IMG) .transition(DrawableTransitionOptions.withCrossFade()) .into(img_thumbnail);

            }
    

    with out transition working fine android.graphics.drawable.TransitionDrawable cannot be cast to com.joooonho.SelectableRoundedImageView$SelectableRoundedCornerDrawable

    opened by Naguchennai 1
  • My selectableRoundedImageView occasionally  lead to picture displaying 1/4 when i use it with Glide.

    My selectableRoundedImageView occasionally lead to picture displaying 1/4 when i use it with Glide.

    My selectableRoundedImageView occasionally lead to picture displaying 1/4 when i use it with Glide. i use it in my application. ` my code

     public void loadNormal(@NonNull SelectableRoundedImageView imageView, @NonNull Object url, int widthDp, int 
      heightDp, int placeholder) {
    
        RequestOptions requestOptions = new RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.RESOURCE);
        if (placeholder != -1) {
            requestOptions.placeholder(placeholder).error(placeholder);
        }
        if (widthDp > 0 && heightDp > 0) {
            requestOptions.override(DeviceUtils.dip2px(imageView.getContext(), widthDp),
                    DeviceUtils.dip2px(imageView.getContext(), heightDp));
        } else if (widthDp > 0) {
            requestOptions.override(DeviceUtils.dip2px(imageView.getContext(), widthDp));
        }
        Glide.with(imageView.getContext())
                .load(getPath(url, imageView))
                .thumbnail(0.6f)
                .apply(requestOptions)
                .into(imageView);
    } `
    

    i have did nothing with it but used glide.

    opened by THEWEWILLBEBACK 0
  • Updated README

    Updated README

    Added .dontAnimate() to Glide part. It prevents some issues with the library. Users should check out Glide's README for options on how to solve this, but for now and to avoid other issues, .dontAnimate() should be included.

    opened by mradzinski 0
Owner
Joonho Kim
Joonho Kim
Adds touch functionality to Android ImageView.

TouchImageView for Android Capabilities TouchImageView extends ImageView and supports all of ImageView’s functionality. In addition, TouchImageView ad

Michael Ortiz 2.6k Jan 1, 2023
A circular ImageView for Android

CircleImageView A fast circular ImageView perfect for profile images. This is based on RoundedImageView from Vince Mi which itself is based on techniq

Henning Dodenhof 14.4k Jan 5, 2023
Custom shaped android imageview components

Shape Image View Provides a set of custom shaped android imageview components, and a framework to define more shapes. Implements both shader and bitma

Siyamed SINIR 2.6k Jan 8, 2023
Android ImageView that handles animated GIF images

GifImageView Android ImageView that handles Animated GIF images Usage In your build.gradle file: dependencies { compile 'com.felipecsl:gifimageview:

Felipe Lima 1.1k Dec 27, 2022
An imageView can auto scroll with device rotating.

PanoramaImageView An imageView can auto scroll with device rotating. ScreenShots Include PanoramaImageView to Your Project With gradle: dependencies {

郭佳哲 2.2k Dec 26, 2022
An image loading and caching library for Android focused on smooth scrolling

Glide | View Glide's documentation | 简体中文文档 | Report an issue with Glide Glide is a fast and efficient open source media management and image loading

Bump Technologies 33.2k Jan 7, 2023
Android Asynchronous Networking and Image Loading

Android Asynchronous Networking and Image Loading Download Maven Git Features Kotlin coroutine/suspend support Asynchronously download: Images into Im

Koushik Dutta 6.3k Dec 27, 2022
A powerful image downloading and caching library for Android

Picasso A powerful image downloading and caching library for Android For more information please see the website Download Download the latest AAR from

Square 18.4k Jan 6, 2023
Powerful and flexible library for loading, caching and displaying images on Android.

Universal Image Loader The great ancestor of modern image-loading libraries :) UIL aims to provide a powerful, flexible and highly customizable instru

Sergey Tarasevich 16.8k Jan 8, 2023
An Android library for managing images and the memory they use.

Fresco Fresco is a powerful system for displaying images in Android applications. Fresco takes care of image loading and display, so you don't have to

Facebook 16.9k Jan 8, 2023
Image loading for Android backed by Kotlin Coroutines.

An image loading library for Android backed by Kotlin Coroutines. Coil is: Fast: Coil performs a number of optimizations including memory and disk cac

Coil 8.8k Jan 8, 2023
An Android view for displaying repeated continuous side scrolling images. This can be used to create a parallax animation effect.

Scrolling Image View An Android view for displaying repeated continuous side scrolling images. This can be used to create a parallax animation effect.

Q42 1.8k Dec 27, 2022
Photo picker library for android. Let's you pick photos directly from files, or navigate to camera or gallery.

ChiliPhotoPicker Made with ❤️ by Chili Labs. Library made without DataBinding, RxJava and image loading libraries, to give you opportunity to use it w

Chili Labs 394 Jan 2, 2023
:ribbon: The simple way to implement a beautiful ribbon with the shimmering on Android.

AndroidRibbon ?? The simple way to implement a beautiful ribbon with the shimmering on Android. 中文語 Download Gradle Add below codes to your root build

Jaewoong Eum 653 Jan 7, 2023
An Android transformation library providing a variety of image transformations for Glide.

Glide Transformations An Android transformation library providing a variety of image transformations for Glide. Please feel free to use this. Are you

Daichi Furiya 9.7k Dec 30, 2022
An android image compression library.

Compressor Compressor is a lightweight and powerful android image compression library. Compressor will allow you to compress large photos into smaller

Zetra 6.7k Jan 9, 2023
An Android transformation library providing a variety of image transformations for Picasso

Picasso Transformations An Android transformation library providing a variety of image transformations for Picasso. Please feel free to use this. Are

Daichi Furiya 1.7k Jan 5, 2023
Media Picker is an Android Libary that lets you to select multiple images or video

Media Picker Please let me know if your application go to production via this link Media Picker is an Android Libary that lets you to select multiple

Abdullah Alhazmy 264 Nov 10, 2022
Library to handle asynchronous image loading on Android.

WebImageLoader WebImageLoader is a library designed to take to hassle out of handling images on the web. It has the following features: Images are dow

Alexander Blom 102 Dec 22, 2022