在Android中用曲线底部绘制矩形视图 [英] Draw Rectangle View with curve bottom In Android

查看:151
本文介绍了在Android中用曲线底部绘制矩形视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Good day.I want to draw an rectangle as a view but which bottom shall be curved.I do not want to apply background image like that or use any views,because if i use an view and set background,the curve part will still have invisible empty space and i would not be able to attach another curve image to the bottom curve of the custom view.So how shall i draw an rectangle with bottom curved line and use it as a view to set any background color i want?

注意:我听到了一些内容,并阅读了有关 quadTo() cubicTo( ) android方法,但我什至不知道如何使用它们,我的意思是我不了解文档中的任何内容...。所以我来这里寻求帮助。

Notice: i have heard something and read about quadTo() and cubicTo() android methods but i have no clue even how to use them i mean i did not understand anything from documents....So i came here for help.

理想地而不是这样的描述,您可以看到我真正想要从图像中实现的目标...它是工具栏,操作栏或其他功能,但是我必须做这样的事情...我一点都不知道(通过这种方式您可以注意到顶部也有弯曲的图像...我没有o也可以这样做,我想我可以通过绘制一个位图来完成。同时我仍然无法在android视图中执行任何图像部分。)

Ideally instead of such description you could see what i really want to achieve from the image...It is an toolbar or action bar or whatsover but i have to make such thing...I have no ideas at all.(By the way you can notice that there is an image curved on top as well...i have to do it too,and i reckon i can do it by drawing an bitmap.meanwhile i'm still failing to do any of the image parts in android view.)

推荐答案

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

Just play with the oval item values to get the desired output.

curve_toolbar_bg .xml

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

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>

这篇关于在Android中用曲线底部绘制矩形视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆