gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:49:10 27 4
gpt4 key购买 nike

美好的一天。我想画一个矩形作为 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com