美好的一天。我想画一个矩形作为 View ,但底部应该是弯曲的。我不想像那样应用背景图像或使用任何 View ,因为如果我使用 View 并设置背景,曲线部分仍然会有看不见的空白空间,我无法将另一个曲线图像附加到自定义 View 的底部曲线。那么我该如何绘制一个带有底部曲线的矩形并将其用作 View 来设置我想要的任何背景颜色?
注意:我听说过一些关于 quadTo()
和 cubicTo()
android 方法的消息,但我什至不知道如何使用它们,我的意思是我没有从文件中理解任何东西....所以我来这里寻求帮助。
理想情况下,您可以看到我真正想从图像中实现什么,而不是这样的描述...它是一个工具栏或操作栏或其他东西,但我必须做这样的事情...我根本没有想法。(顺便说一句,你可以注意到顶部也有一个弯曲的图像......我也必须这样做,我想我可以通过绘制位图来做到这一点。同时我仍然没有做任何图像android View 中的零件。)
最佳答案
只需使用椭圆形项目值即可获得所需的输出。
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>
关于android - 在Android中绘制带曲线底部的矩形 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39493293/