android imageview shape 圆角,android-shape-imageview - 图片圆角、三角、五角、圆形、多角...

Shape Image View

625332134c6f4d4600884b99daebf603.png625332134c6f4d4600884b99daebf603.png

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

Mask based one uses xfermode to draw image on bitmaps defined by android shape XML's or resource bitmaps.

625332134c6f4d4600884b99daebf603.png

625332134c6f4d4600884b99daebf603.png

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.

How to use

Gradle dependency:

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

###Shader Based ImageView's ####BubbleImageView 625332134c6f4d4600884b99daebf603.png

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 625332134c6f4d4600884b99daebf603.png

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 625332134c6f4d4600884b99daebf603.png

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

DiamondImageView

PentagonImageView

HexagonImageView

625332134c6f4d4600884b99daebf603.png

625332134c6f4d4600884b99daebf603.png

625332134c6f4d4600884b99daebf603.png

OctogonImageView

StarImageView

HeartImageView

625332134c6f4d4600884b99daebf603.png

625332134c6f4d4600884b99daebf603.png

625332134c6f4d4600884b99daebf603.png

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 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.

625332134c6f4d4600884b99daebf603.png

android:layout_width="match_parent"

android:layout_height="match_parent"

app:siShape="@drawable/star"

android:src="@drawable/neo"

app:siSquare="true"/>

625332134c6f4d4600884b99daebf603.png

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:

android:topLeftRadius="18dp"

android:topRightRadius="18dp"

android:bottomLeftRadius="18dp"

android:bottomRightRadius="18dp" />

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

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

MostafaGazar/CustomShapeImageView: Used this project a basis for bitmap masks

geosolutions-it/mapsforge/svg-android: Used and modified to create a path from a svg file

625332134c6f4d4600884b99daebf603.png

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值