在曲线底部绘制矩形视图在Android中

问题描述 投票:4回答:2

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

注意:我已经听过一些关于quadTo()cubicTo()安卓方法的内容,但我不知道如何使用它们我的意思是我从文​​档中什么都不懂......所以我来这里寻求帮助。

理想情况下,您可以从图像中看到我真正希望实现的内容......它是一个工具栏或操作栏或者其他什么,但我必须做出这样的事情......我根本就没有想法。(顺便说一下)你可以注意到顶部有一个弯曲的图像......我也必须这样做,我想我可以通过绘制一个bitmap.mean而我仍然无法在android中做任何图像部分图。)enter image description here

android canvas view draw cube
2个回答
22
投票

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

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


2
投票

嘿经过this link。它将帮助您制作所需视图的底部形状。

© www.soinside.com 2019 - 2024. All rights reserved.