You need to draw the curves using Cubic Bézier Curve
. A good article to know how to draw such curves is written by Bartosz Ciechanowski, here.
I have developed a View
to draw a shape like google pay which inherits from FrameLayout
. The source code is available on its github repository (but not documented yet!). However, add the following lines to your app level build.gradle
file:
repositories {
jcenter()
}
dependencies {
implementation 'com.aminography:beziercurvebulgelayout:1.0.2'
}
Then you can use it in xml
layout files as following:
<com.aminography.view.BezierCurveBulgeLayout
android:id="@+id/bulgeLayout"
android:layout_width="match_parent"
android:layout_height="56dp"
app:bulgeType="bulge"
app:bulgeColor="@color/colorPrimary"
app:curveWidth="32dp"
app:flatWidth="56dp"
app:flatHeight="24dp">
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@android:drawable/ic_menu_compass"/>
</com.aminography.view.BezierCurveBulgeLayout>
.
Its shape and color is customizable to achieve the target shape by changing below attributes:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…