Roundedimageview
A Fast ImageView (and drawable) that supports rounded corners (and ovals or circles) based on the original example from Ro Main guy. Roundedimageview is a full superset of Circleimageview (which was actually just a subset based on this lib) with many more Advanced features like support for ovals, rounded rectangles, scaletypes and tilemodes.
There is many ways to create rounded corners on Android, but this is the fastest and best one that I know of because it:
- Does not create a copy of the original bitmap
- Does not use a clippath which are not hardware accelerated and not anti-aliased.
- Does not use Setxfermode to clip the bitmap and draw twice to the canvas.
If you know of a better method, let me know (or even better open a pull request)!
Also have proper support for:
- Borders (with Colors and colorstatelists)
- Ovals and Circles
- All
ScaleType S
- Borders is drawn at view edge, not bitmap edge
- Except on edges where the bitmap is smaller than the view
- Borders is not scaled Up/down with the image (correct width and radius is maintained)
- Anti-aliasing
- Transparent Backgrounds
- Hardware acceleration
- Support for Layerdrawables (including transitiondrawables)
- Tilemodes for repeating Drawables
Gradle
Roundedimageview is available on Maven Central.
Add the following to your for use build.gradle :
repositories { mavenCentral()}dependencies { compile ‘com.makeramen:roundedimageview:2.2.0‘}
Usage
Define in XML:
<Com.makeramen.roundedimageview.RoundedImageViewxmlns:app="Http://schemas.android.com/apk/res-auto"Android:Id="@+id/imageview1"Android:Src="@drawable/photo1"Android:Scaletype="Fitcenter"App:riv_corner_radius="30dip "app:riv_border_width= "2dip" app:< Span class= "PL-E" >riv_border_color= "#333333 app:riv_mutate_background= "True" app: Riv_tile_mode= "Repeat" app:riv_oval= "True"/
Or in code:
Roundedimageview Riv=NewRoundedimageview (context); Riv. Setscaletype (ScaleType. Center_crop); Riv. Setcornerradius (float) 10) riv.setborderwidth ((float) 2) ; Riv.setbordercolor (color.mutatebackground (true); Riv.setbackground (backgrounddrawable); Rivtrue) riv.settilemodex (Shader tilemode.settilemodey (shader. Tilemode
Or make a transformation for Picasso:
Roundedtransformationbuilder () . BorderColor (Color. BLACK). BORDERWIDTHDP (3). CORNERRADIUSDP (.). Oval (false). Build (); Picasso. With(context). Load (URL). Fit (). Transform (Transformation). to (ImageView);
Changelog
See releases
Project Address: Https://github.com/vinc3m1/RoundedImageView
A rounded picture in Android