A rounded picture in Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.