Tuesday 30 October 2018

How to create Different Shapes

Different ShapeView

dependencies {
    implementation 'com.github.florent37:shapeofview:(lastest version)'
} 
       Version 1.4.0
1.0.0
Circle
<com.github.florent37.shapeofview.shapes.CircleView
android:layout_width="150dp"
android:layout_height="150dp"

android:elevation="4dp"
app:shape_circle_borderColor="@android:color/black"
app:shape_circle_borderWidth="2dp">

<!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.CircleView>

RoundRect
<com.github.florent37.shapeofview.shapes.RoundRectView
android:layout_width="150dp"
android:layout_height="100dp"
android:elevation="4dp"
app:shape_roundRect_bottomLeftRadius="10dp"
app:shape_roundRect_bottomRightRadius="10dp"
app:shape_roundRect_topLeftRadius="10dp"
app:shape_roundRect_topRightRadius="10dp"

app:shape_roundRect_borderColor="@android:color/black"
app:shape_roundRect_borderWidth="2dp"
        >


<!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.RoundRectView>


ClipCorner
<com.github.florent37.shapeofview.shapes.CutCornerView
android:id="@+id/clipCorner"
android:layout_width="150dp"
android:layout_height="100dp"
android:elevation="4dp"
app:shape_cutCorner_bottomRightSize="20dp">

<!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.CutCornerView>


Arc
<com.github.florent37.shapeofview.shapes.ArcView
android:layout_width="150dp"
android:layout_height="100dp"
android:elevation="4dp"
app:shape_arc_cropDirection="outside"
app:shape_arc_height="20dp"
app:shape_arc_position="bottom"
        >

<!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.ArcView>


Diagonal
<com.github.florent37.shapeofview.shapes.DiagonalView
android:layout_width="150dp"
android:layout_height="100dp"
android:elevation="4dp"
app:shape_diagonal_angle="10"
app:shape_diagonal_direction="left"
app:shape_diagonal_position="bottom">

<!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.DiagonalView>


Triangle
<com.github.florent37.shapeofview.shapes.TriangleView
android:layout_width="150dp"
android:layout_height="150dp"
android:elevation="4dp"

app:shape_triangle_percentBottom="0.5"
app:shape_triangle_percentLeft="0"
app:shape_triangle_percentRight="0">

<!-- YOUR CONTENT -->
</com.github.florent37.shapeofview.shapes.TriangleView>


Bubble
<com.github.florent37.shapeofview.shapes.BubbleView
android:layout_width="150dp"
android:layout_height="150dp"
app:shape_bubble_arrowHeight="10dp"
app:shape_bubble_arrowWidth="10dp"
app:shape_bubble_arrowPosition="bottom"
app:shape_bubble_borderRadius="20dp"
        >

<!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.BubbleView>


Star
<com.github.florent37.shapeofview.shapes.StarView
android:layout_width="150dp"
android:layout_height="150dp"
app:shape_star_noOfPoints="5">

<!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.StarView>


Polygon
<com.github.florent37.shapeofview.shapes.PolygonView
android:layout_width="150dp"
android:layout_height="100dp"
app:shape_polygon_noOfSides="9"
            >
<!-- YOUR CONTENT -->

</com.github.florent37.shapeofview.shapes.PolygonView>



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


Using Drawable (no elevation)
<com.github.florent37.shapeofview.ShapeOfView
android:layout_width="100dp"
android:layout_height="100dp"

app:shape_clip_drawable="@drawable/YOUR_DRAWABLE"
        >

<!-- YOUR CONTENT -->

 </com.github.florent37.shapeofview.ShapeOfView>


Using Path (with elevation)
<com.github.florent37.shapeofview.ShapeOfView
android:id="@+id/myShape"
android:layout_width="30dp"
android:layout_height="15dp"
android:elevation="6dp">

<!-- YOUR CONTENT -->

 </com.github.florent37.shapeofview.ShapeOfView>


Then generate a path in your code :
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;
       }
});


//Reference link
https://github.com/florent37/ShapeOfView

No comments:

Post a Comment

HOW TO CREATE CIRCLE IMAGE VIEW

Step 1: implementation 'de.hdodenhof:circleimageview:3.0.0' Step 2: <de.hdodenhof.circleimageview.CircleImageView xmlns:ap...