Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/florent37/ShapeOfView

Give a custom shape to any android view, Material Design 2 ready
https://github.com/florent37/ShapeOfView

android androidx custom layout mask material shape view xml

Last synced: 3 months ago
JSON representation

Give a custom shape to any android view, Material Design 2 ready

Lists

README

        

# ShapeOfView

[![CircleCI](https://circleci.com/gh/florent37/ShapeOfView/tree/master.svg?style=svg)](https://circleci.com/gh/florent37/ShapeOfView/tree/master)

Give a custom shape to any android view
Useful for Material Design 2

[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/shrine.gif)](https://www.github.com/florent37/ShapeOfView)
[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/sample_diagonal.gif)](https://www.github.com/florent37/ShapeOfView)
[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/sample_arc.gif)](https://www.github.com/florent37/ShapeOfView)


Android app on Google Play

*Breaking change*

the old package `com.github.florent37` has been replaced by `io.github.florent37`

# Download

Buy Me a Coffee at ko-fi.com

[ ![Download](https://api.bintray.com/packages/florent37/maven/shapeofview/images/download.svg) ](https://bintray.com/florent37/maven/shapeofview/)
```java
//using maven central

dependencies {
implementation 'io.github.florent37:shapeofview:1.4.7'
}
```

# Sample

What you can do with Shape Of View :

[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/tab.gif)](https://www.github.com/florent37/ShapeOfView)

# Use implemented shapes

ShapeOfView **disable** the `background` property of your view,
please specify a child with a background to enable it
```xml

```

## RoundRect

[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/roundrect.png)](https://www.github.com/florent37/ShapeOfView)

```xml

```

## ClipCorner

[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/cut_corner.png)](https://www.github.com/florent37/ShapeOfView)

```xml

```

## Arc

[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/arc.png)](https://www.github.com/florent37/ShapeOfView)

```xml

```

## Diagonal

[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/diagonal.png)](https://www.github.com/florent37/ShapeOfView)

```xml

```

## Triangle

[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/triangle.png)](https://www.github.com/florent37/ShapeOfView)

```xml

```

## Bubble

[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/bubble.png)](https://www.github.com/florent37/ShapeOfView)

```xml

```

## Star

[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/star_5_pointed.png)](https://www.github.com/florent37/ShapeOfView)
[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/star_11_pointed.png)](https://www.github.com/florent37/ShapeOfView)

```xml

```

## Polygon

[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/polygon.png)](https://www.github.com/florent37/ShapeOfView)

```xml

```

## Dotted Edges with Cut Corners

[![screen](medias/edges_corners.png)](https://www.github.com/florent37/ShapeOfView)

```xml


```

## Animation

All shapes methods can be animated

For example, you can animate a RoundRect corner :

[![anim](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/shapeofview_anim.gif)](https://www.github.com/florent37/ShapeOfView)

```kotlin
ValueAnimator.ofFloat(0f, 200f, 0f).apply {
addUpdateListener { animation -> roundRect.bottomLeftRadius = (animation.animatedValue as Float).toInt() }
duration = 800
repeatCount = ValueAnimator.INFINITE
repeatMode = ValueAnimator.REVERSE
}.start()
```

# Create you own shape

You can use custom shape to cut your view

# Using Drawable (no elevation)

[![screen](https://raw.githubusercontent.com/florent37/ShapeOfView/master/medias/custom.png)](https://www.github.com/florent37/ShapeOfView)

```xml


```

# Using Path (with elevation)

This method generates also a **shadow path** (with Lollipop elevation API 21+)

Wrap your view with a `ShapeOfView`

```xml


```

Then generate a path in your code :

```java
ShapeOfView shapeOfView = findViewById(R.id.myShape)
shapeOfView.setClipPathCreator(new ClipPathManager.ClipPathCreator() {
@Override
public Path createClipPath(int width, int height) {
final Path path = new Path();

//eg: triangle
path.moveTo(0, 0);
path.lineTo(0.5 * width, height);
path.lineTo(width, 0);
path.close();

return path;
}
});
```

In some case you have to specify `requiresBitmap = true` to enable ShapeOfView to draw the shape inside a bitmap before clipping your view. It will be less efficient but can make your custom shape work.

# Contribute

Feel free to fork this project, and add customs shapes

Then make a `merge-request` after updated the README with a sample of your shape, including a preview

# TODO

# HISTORY

**1.4.5** Removed DiagonalView's Direction : if diagonalAngle > 0 ? DIRECTION_LEFT : DIRECTION_RIGHT

**1.4.5** Removed ArcView's ArcDirection : CROP_OUTSIDE if arcHeight > 0, CROP_INSIDE if arcHeight < 0

**1.4.1** Added Dotted Edge, thanks to @khunzohn

**1.4.0** Support AndroidX

**1.3.2** Backport of 1.3.0 for api 14+

**1.3.0** Fixed rendering on android API 28+

**1.2.0** Removed bitmap usage in a lot of usecases (diagonal, arc, roundrect, circle)

**1.1.0** Disabled setBackground on ShapeOfView

**1.0.9** Added requiresShapeUpdate(), allowing animations to work, look at AnimationActivity

**1.0.8** Used arcTo instead of quads in RoundRect, added border to RoundRect

**1.0.7** Prefixed all attributes by `shape_`

**1.0.6** Updated roundrect implementation

**1.0.5** Enable hardware acceleration after clip view

**1.0.4** Added PolygonView

**1.0.2** Added StarView

**1.0.1** Added BubbleView

# Credits

Ed Sheeran, for the name of this project and his awesome songs <3

Author: Florent Champigny

Blog : [http://www.tutos-android-france.com/](http://www.tutos-android-france.com/)

Fiches Plateau Moto : [https://www.fiches-plateau-moto.fr/](https://www.fiches-plateau-moto.fr/)


Android app on Google Play


Follow me on Google+


Follow me on Twitter


Follow me on LinkedIn

License
--------

Copyright 2017 Florent37, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.