android - 在Android中绘制带曲线底部的矩形 View

标签 android canvas view draw cube

美好的一天。我想画一个矩形作为 View ,但底部应该是弯曲的。我不想像那样应用背景图像或使用任何 View ,因为如果我使用 View 并设置背景,曲线部分仍然会有看不见的空白空间,我无法将另一个曲线图像附加到自定义 View 的底部曲线。那么我该如何绘制一个带有底部曲线的矩形并将其用作 View 来设置我想要的任何背景颜色?

注意:我听说过一些关于 quadTo()cubicTo() android 方法的消息,但我什至不知道如何使用它们,我的意思是我没有从文件中理解任何东西....所以我来这里寻求帮助。

理想情况下,您可以看到我真正想从图像中实现什么,而不是这样的描述...它是一个工具栏或操作栏或其他东西,但我必须做这样的事情...我根本没有想法。(顺便说一句,你可以注意到顶部也有一个弯曲的图像......我也必须这样做,我想我可以通过绘制位图来做到这一点。同时我仍然没有做任何图像android View 中的零件。)enter image description here

最佳答案

只需使用椭圆形项目值即可获得所需的输出。

curve_toolbar_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle"/>
    </item>
    <item
        android:bottom="0dp"
        android:left="-100dp"
        android:right="-100dp"
        android:top="-80dp">
        <shape android:shape="oval">
            <solid android:color="@color/colorPrimary" />
        </shape>
    </item>
</layer-list>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="0dp"
        android:layout_height="?android:attr/actionBarSize"
        android:background="@drawable/curve_toolbar_bg"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0">

    </android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>

Curve shape toolbar

关于android - 在Android中绘制带曲线底部的矩形 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39493293/

相关文章:

android - 如何在android中实现陀螺仪传感器?

Android:如何在 GLSurfaceView 上显示 admob 广告

java - 更新后使用 Android Studio 创建新项目时出现问题

android - 在代码中发誓

sql - Oracle 可以使用 PARTITION BY 分析函数对查询使用谓词推送吗?

android - 如何在 onDraw 方法中创建和显示 ListView ?

javascript - Canvas |在从 SVG 创建过程中如何设置 Canvas 元素的样式?

javascript - 使基于 Canvas 滚动的图像序列动画更加流畅

javascript - 如何替换 Canvas onclick 上的图像?

sql - 我的 VIEW 语句出现 "missing right parenthesis"错误 (Oracle)