All Projects → fievx → View_shaper

fievx / View_shaper

A library to help create shaped views and layouts in Android

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to View shaper

Shapeofview
Give a custom shape to any android view, Material Design 2 ready
Stars: ✭ 2,977 (+6988.1%)
Mutual labels:  xml, shape, layout
Phidl
Python GDS layout and CAD geometry creation
Stars: ✭ 56 (+33.33%)
Mutual labels:  shape, layout
Flexlib
FlexLib是一个基于flexbox模型,使用xml文件进行界面布局的框架,融合了web快速布局的能力,让iOS界面开发像写网页一样简单快速
Stars: ✭ 1,569 (+3635.71%)
Mutual labels:  xml, layout
Interfacss
The CSS-inspired styling and layout framework for iOS
Stars: ✭ 92 (+119.05%)
Mutual labels:  xml, layout
bpmn-layout-generators
Tools for generating missing BPMNDiagram elements in BPMN files
Stars: ✭ 27 (-35.71%)
Mutual labels:  shape, layout
SquareImageView
SquareImageView is a simple wrapper library for Android ImageView
Stars: ✭ 28 (-33.33%)
Mutual labels:  shape, layout
Motion Shapeofview
Explain how to use MotionLayout with ShapeOfView
Stars: ✭ 236 (+461.9%)
Mutual labels:  shape, layout
ShadowDrawable
为View 和 ViewGroup 添加阴影效果--Android,Add shadow for single view or viewgroup layout.
Stars: ✭ 22 (-47.62%)
Mutual labels:  layout, viewgroup
bubble-layout
An Android ViewGroup that displays avatar bubbles... similar to the chat bubbles on Facebook Messenger.
Stars: ✭ 46 (+9.52%)
Mutual labels:  layout, viewgroup
Backgroundlibrary
A framework for directly generating shape through Tags, no need to write shape.xml again(通过标签直接生成shape,无需再写shape.xml)
Stars: ✭ 3,179 (+7469.05%)
Mutual labels:  xml, shape
Extendededges
A simple and easy way to keep your custom views properly layout on iPhone X.
Stars: ✭ 31 (-26.19%)
Mutual labels:  layout
Animeavataar
creating Anime Avataar from a facial image
Stars: ✭ 31 (-26.19%)
Mutual labels:  shape
Readablebottombar
Yet another material bottom bar library for Android
Stars: ✭ 977 (+2226.19%)
Mutual labels:  layout
Flutter Neumorphic
A complete, ready to use, Neumorphic ui kit for Flutter, 🕶️ dark mode compatible
Stars: ✭ 988 (+2252.38%)
Mutual labels:  shape
Texture
A visual editor for research.
Stars: ✭ 958 (+2180.95%)
Mutual labels:  xml
Xml
XML without worries
Stars: ✭ 35 (-16.67%)
Mutual labels:  xml
Evreflection
Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift
Stars: ✭ 954 (+2171.43%)
Mutual labels:  xml
Collectionviewpaginglayout
a simple but highly customizable paging layout for UICollectionView.
Stars: ✭ 947 (+2154.76%)
Mutual labels:  layout
Yaidom
Yet another immutable XML DOM-like API
Stars: ✭ 27 (-35.71%)
Mutual labels:  xml
Rwidgethelper
Android UI 快速开发,专治原生控件各种不服
Stars: ✭ 996 (+2271.43%)
Mutual labels:  shape

view_shaper

A library to help create shaped views and layouts in Android

If you can write a Path representing the shape that you need, you can use ViewShaper to clip any View following the path and draw a shadow.

This is a nice solution when the desired shape is more complex than a circle or a square and you cannot create a XML Shape to use as background of your View.

Implementation:

Create a Custom View extending ViewShaper. ViewShaper has a method abstract fun getShaper(): Shaper? which you must override to return a Shaper.

Shaper is an Inerface:

interface Shaper {
    fun getPath(width: Int, height: Int): Path
}

So a simple implementation of a custom view overriding a ViewShaper could look like this:

class WeirdViewShaper @JvmOverloads constructor(
        context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : ViewShaper(context, attrs, defStyleAttr) {

    override fun getShaper(): Shaper? {
        return object : Shaper{
            override fun getPath(width: Int, height: Int): Path {
                val centerX = width/2f
                val centerYTop = height/3f
                val centerYBottom = height - height/3f
                val right = width.toFloat()
                val bottom = height.toFloat()
                return Path().apply {
                    moveTo(0f, 0f)
                    lineTo(centerX, centerYTop)
                    lineTo(right, 0f)
                    lineTo(right, bottom)
                    lineTo(centerX, centerYBottom)
                    lineTo(0f, bottom)
                    close()
                }
            }
        }
    }
}

You now have a layout that will accept a single child (much like a ScrollView). This Single child can be a View or a ViewGroup. And you can obviously have a ViewShaper inside a ViewShaper since a ViewShaper is just a ViewGroup.

        <android.support.constraint.ConstraintLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            >

            <ImageView
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                android:background="@color/colorAccent" />

            <com.example.denais.testapplication.viewshaper.WeirdViewShaper
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:padding="3dp">

                <TextView
                    android:id="@+id/bt_shadow"
                    android:text="Another shape just for the fun"
                    android:layout_height="50dp"
                    android:layout_width="wrap_content"
                    android:background="@color/colorPrimary"
                    android:gravity="center"
                    android:textColor="@color/black"
                    android:padding="10dp"/>
            </com.example.denais.testapplication.viewshaper.WeirdViewShaper>

        </android.support.constraint.ConstraintLayout>

image

Install:

This library is available using jitpack.

Step 1. Add the JitPack repository to your build file.

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.fievx:view_shaper:v1.0.0'
}

Note

The idea for this library came when I hade to create a custom view shaped as a movie ticket. I realised that the usual methods were not sufficient for my needs.

You can find my research and thought process in a blog post I wrote when working on this custom view and library. https://medium.com/@denais.jeremy/shaping-views-in-android-cheat-sheet-fd4687f5da5a

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].