Android在谷歌支付中绘制自定义视图

Android在谷歌支付中绘制自定义视图

本文介绍了Android在谷歌支付中绘制自定义视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经被提出并且答案已经被接受,但可接受的答案不是我想要的.我想使用一个customview,其中的槽口采用宽度+所经过的视图的某些边距,例如上图中的付款图标.在查看底部有一个fab之类的底部应用程序栏时,例如我看到了一个名为边缘处理类的类猜想也可以使用.我现在不会发布我的customview代码,因为我所能绘制的只是一个矩形.

This question has already been asked and an answer has been accepted here but the accepted answer is not what I am looking for. I want to use a customview in which the notch takes the width + some margin of the view which it is going over, like the pay icon in the above image. While looking into the bottomappbar which houses a fab like thisI saw a class called the edge treatment class I guess that can be used as well. I am not posting my customview code rightnow as all I could draw is a rectangle.

推荐答案

您需要使用 Cubic Bézier Curve . Bartosz Ciechanowski写了一篇很好的文章,知道如何绘制这样的曲线,这里.

我开发了View来绘制类似Google pay的形状,该形状继承自FrameLayout.源代码可在其github存储库中使用(但尚未记录!).但是,将以下几行添加到您的应用级build.gradle文件中:

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'
}

然后您可以在xml布局文件中使用它,如下所示:

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:

这篇关于Android在谷歌支付中绘制自定义视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 11:40