Coder Social home page Coder Social logo

roundedimageview's Introduction

RoundedImageView

A fast ImageView (and Drawable) that supports rounded corners based on the original example from Romain Guy

RoundedImageView screenshot

There are many ways to create rounded corners in 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 is 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 and I'll implement it!

Also has proper support for:

  • Borders (with Colors and ColorStateLists)
  • All ScaleTypes
    • Borders are drawn at view edge, not bitmap edge.
    • Except on edges where the bitmap is smaller than the view
    • Borders are not scaled up/down with the image (correct width and radius are maintained)
  • Anti-aliasing
  • Transparent backgrounds
  • Hardware acceleration
  • Support for TransitionDrawables (XML attrs only)

Gradle

RoundedImageView is available on Ark.

Add the following to your build.gradle to use:

repositories {
    maven {
        url 'https://raw.github.com/ark/ark/master/releases/'
    }
}

dependencies {
    compile 'com.makeramen:roundedimageview:1.0.0'
}

Maven

Make sure you installed Android 4.2 from the Android Maven Deployer

Build the apk:

git clone https://github.com/vinc3m1/RoundedImageView.git
cd ./RoundedImageView/
mvn clean install

Install and run:

cd ./example
mvn android:deploy android:run

If you want to use the library, add this dependency:

<dependency>
    <groupId>com.makeramen.rounded</groupId>
    <artifactId>library</artifactId>
    <version>0.1</version>
    <type>apklib</type>
</dependency>

Use Library

Define in xml:

<com.makeramen.RoundedImageView
        xmlns:makeramen="http://schemas.android.com/apk/res/com.makeramen.rounded.RoundedImageView"
        android:id="@+id/imageView1"
        android:src="@drawable/photo1"
        android:scaleType="centerCrop"
        makeramen:corner_radius="30dip"
        makeramen:border="2dip"
        makeramen:border_color="#333333"
        makeramen:round_background="true" />

Or in code:

RoundedImageView iv = new RoundedImageView(context);
iv.setScaleType(ScaleType.CENTER_CROP);
iv.setCornerRadius(10);
iv.setBorderWidth(2);
iv.setBorderColor(Color.DKGRAY);
iv.setRoundedBackground(true);
iv.setImageDrawable(drawable);
iv.setBackground(backgroundDrawable);

Known Issues

  • Programmatically setting attributes with TransitionDrawables not yet supported.
  • Only tested support for BitmapDrawables and TransitionDrawables (with BitmapDrawables in them). Other types might work but may have unexpected behavior.

roundedimageview's People

Contributors

vinc3m1 avatar kolipass avatar

Watchers

James Cloos avatar Yanto Young avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.