Convert Figma logo to code with AI

siyamed logoandroid-shape-imageview

Custom shaped android imageview components

2,664
598
2,664
63

Top Related Projects

Create circular ImageView in Android in the simplest way possible

A fast ImageView that supports rounded corners, ovals, and circles.

Quick Overview

Android-shape-imageview is a custom ImageView library for Android that allows developers to display images in various shapes, such as circles, rounded rectangles, and custom SVG shapes. It provides a simple and efficient way to create visually appealing image views without the need for complex image processing or manual shape drawing.

Pros

  • Easy to implement and integrate into existing Android projects
  • Supports a wide variety of shapes, including circles, rounded rectangles, and custom SVG shapes
  • Efficient rendering with minimal impact on performance
  • Customizable attributes for fine-tuning the appearance of shaped images

Cons

  • Limited documentation and examples for advanced use cases
  • May not support all image formats or edge cases
  • Potential compatibility issues with older Android versions
  • Lack of recent updates or maintenance (last updated in 2015)

Code Examples

  1. Creating a circular image view:
<com.github.siyamed.shapeimageview.CircularImageView
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:src="@drawable/sample_image"
    app:siBorderWidth="4dp"
    app:siBorderColor="#000000"/>
  1. Creating a rounded rectangle image view:
<com.github.siyamed.shapeimageview.RoundedImageView
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:src="@drawable/sample_image"
    app:siRadius="10dp"
    app:siBorderWidth="2dp"
    app:siBorderColor="#FF0000"/>
  1. Using a custom SVG shape:
<com.github.siyamed.shapeimageview.mask.PorterShapeImageView
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:src="@drawable/sample_image"
    app:siShape="@drawable/custom_shape_svg"/>

Getting Started

To use android-shape-imageview in your project, follow these steps:

  1. Add the JitPack repository to your project's build.gradle file:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.github.siyamed:android-shape-imageview:0.9.3@aar'
}
  1. Sync your project with Gradle files.

  2. Use the custom ImageView classes in your XML layouts or create them programmatically in your Java/Kotlin code.

Competitor Comparisons

Create circular ImageView in Android in the simplest way possible

Pros of CircularImageView

  • Simpler API focused specifically on circular images
  • More recent updates and active maintenance
  • Better performance for circular images due to specialized implementation

Cons of CircularImageView

  • Limited to circular shapes only, less versatile than android-shape-imageview
  • Fewer customization options for borders and shadows

Code Comparison

CircularImageView:

<com.mikhaellopez.circularimageview.CircularImageView
    android:layout_width="250dp"
    android:layout_height="250dp"
    app:civ_border_color="#3f51b5"
    app:civ_border_width="4dp"
    app:civ_shadow="true"
    app:civ_shadow_radius="10"
    app:civ_shadow_color="#3f51b5"/>

android-shape-imageview:

<com.github.siyamed.shapeimageview.CircularImageView
    android:layout_width="120dp"
    android:layout_height="120dp"
    app:siBorderWidth="6dp"
    app:siBorderColor="@color/darkgray"
    app:siSquare="true"/>

CircularImageView offers a more straightforward implementation for circular images with built-in shadow support, while android-shape-imageview provides more shape options but requires additional configuration for similar effects.

A fast ImageView that supports rounded corners, ovals, and circles.

Pros of RoundedImageView

  • More actively maintained with recent updates
  • Supports oval and circular shapes in addition to rounded corners
  • Offers better performance optimization for large images

Cons of RoundedImageView

  • Limited to rounded shapes only, lacks support for other geometric shapes
  • Doesn't provide built-in border drawing functionality

Code Comparison

RoundedImageView:

<com.makeramen.roundedimageview.RoundedImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:riv_corner_radius="30dip"
    app:riv_border_width="2dip"
    app:riv_border_color="#333333"
    app:riv_mutate_background="true"
    app:riv_tile_mode="repeat"
    app:riv_oval="true" />

android-shape-imageview:

<com.github.siyamed.shapeimageview.RoundedImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:siBorderWidth="2dp"
    app:siBorderColor="#000000"
    app:siRadius="8dp" />

RoundedImageView offers more customization options in XML, including oval shape and background mutation. android-shape-imageview provides a simpler implementation for basic rounded corners and borders.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Shape Image View

Maven Central

Provides a set of custom shaped android imageview components, and a framework to define more shapes. Implements both shader and bitmap mask based image views.

  • Shader based one uses canvas draw methods and Path class,
  • Mask based one uses xfermode to draw image on bitmaps defined by android shape XML's or resource bitmaps.

There are many projects online implementing such components, however one goal of this project is to provide a performant/smooth scrolling image view component framework to define different shapes for imageviews.

For use with recycling view such as ListView or GridView please use shader based implementations.

Sample app in play store

Youtube video

How to use

Gradle dependency:

compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'

###Shader Based ImageView's ####BubbleImageView Android Bubble ImageView

<com.github.siyamed.shapeimageview.BubbleImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/neo"
    app:siArrowPosition="right"
    app:siSquare="true"/>

Attributes:

  • siTriangleHeight the height of the bubble pointer in dp
  • siArrowPosition where to point the arrow, currently left|right
  • siSquare set width and height to the minimum of the given values true|false

####RoundedImageView Android Rounded Rectangle ImageView

<com.github.siyamed.shapeimageview.RoundedImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/neo"
    app:siRadius="6dp"
    app:siBorderWidth="6dp"
    app:siBorderColor="@color/darkgray"
    app:siSquare="true"/>

Attributes:

  • siBorderColor border color
  • siBorderWidth border width in dp
  • siBorderAlpha alpha value of the border between 0.0-1.0
  • siRadius corner radius in dp
  • siSquare set width and height to the minimum of the given values true|false

####CircularImageView Android Circular ImageView

<com.github.siyamed.shapeimageview.CircularImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/neo"
    app:siBorderWidth="6dp"
    app:siBorderColor="@color/darkgray"/>

Attributes:

  • siBorderColor border color
  • siBorderWidth border width in dp
  • siBorderAlpha alpha value of the border between 0.0-1.0

####ShapeImageView This view has the capability to process a provided SVG file (for a limited set of SVG elements), build a Path object and draw it on the shader. The library includes SVG files defining a set of basic shapes and ShapeImageView subclasses using those files. You can use whatever SVG you want to have a wonderful and creatively shaped images in your application. The included SVG files are under library/src/main/res/raw

DiamondImageViewPentagonImageViewHexagonImageView
Android Diamond ImageViewAndroid Pentagon ImageViewAndroid Hexagon ImageView
OctogonImageViewStarImageViewHeartImageView
Android Octogon ImageViewAndroid Start ImageViewAndroid Heart ImageView
<com.github.siyamed.shapeimageview.{ClassName}
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="8dp"
    android:src="@drawable/neo"
    app:siBorderWidth="8dp"
    app:siBorderColor="@color/darkgray"/>

Attributes:

  • siBorderColor border color
  • siBorderWidth border width in dp
  • siBorderAlpha alpha value of the border between 0.0-1.0
  • siStrokeCap border stroke cap type butt|round|square
  • siStrokeJoin border stroke join type bevel|miter|round
  • siSquare set width and height to the minimum of the given values true|false
  • siShape a reference to an SVG. This is used by ShapeImageView, not the subclasses of it.

SVG elements that are supported are: rectangle, circle, ellipse, polygon, path, group. Transformations on those elements are also supported.

The system converts an SVG file into a Path. For each element including the parent element <svg> a new Path is created, and all the children Path's are added to their parent path.

###Bitmap Mask Based ImageViews

This view uses extra bitmaps for bitmap masks. Therefore it would be good to use them for very custom shapes, possibly not in a recycling view.

Android Star Shape ImageView

<com.github.siyamed.shapeimageview.mask.PorterShapeImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:siShape="@drawable/star"
    android:src="@drawable/neo"
    app:siSquare="true"/>

Android Star Shape ImageView

<com.github.siyamed.shapeimageview.mask.PorterShapeImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:siShape="@drawable/shape_rounded_rectangle"
    android:src="@drawable/neo"
    app:siSquare="true"/>

rounded rectangle shape definition in XML:

<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
    <corners
        android:topLeftRadius="18dp"
        android:topRightRadius="18dp"
        android:bottomLeftRadius="18dp"
        android:bottomRightRadius="18dp" />
    <solid android:color="@color/black" />
</shape>

Attributes:

  • siShape the bitmap mask shape, either a shape drawable or a bitmap
  • siSquare set width and height to the minimum of the given values true|false

This method reads a shape file (either bitmap or an android shape xml), creates a bitmap object using this shape, and finally combines the bitmap of the real image to be shown and the mast bitmap using xfermode.

Sample

See/execute the sample for a demonstration of the components.

If you are lazy check this youtube video demonstrating scrolling in the sample app

You can download the sample app from play store

Proguard

-dontwarn android.support.v7.**
-keep class android.support.v7.** { ; }
-keep interface android.support.v7.* { ; }
-keepattributes *Annotation,Signature
-dontwarn com.github.siyamed.**
-keep class com.github.siyamed.shapeimageview.**{ *; }

References

Android Shape Image View on Android Arsenal