绘制矩形视图与曲线底部在Android中
问题描述:
好日子。我想绘制一个矩形作为视图,但底部应弯曲。我不想应用这样的背景图像或使用任何视图,因为如果我使用查看和设置背景时,曲线部分仍然会有不可见的空白空间,我将无法将另一个曲线图像附加到自定义视图的底部曲线。因此,如何绘制具有底部曲线的矩形并将其用作查看设置我想要的任何背景颜色?绘制矩形视图与曲线底部在Android中
注意:我听说过一些和阅读有关quadTo()
和cubicTo()
Android的方法,但我不知道,甚至如何使用我的意思是我不理解文件什么....所以我来到这里寻求帮助。
理想情况下,而不是这样的描述,你可以看到我真的想从图像中实现...这是一个工具栏或操作栏或任何东西,但我必须做出这样的事情......我根本没有任何想法。 (顺便说一下,您可以注意到顶部也有一个图像弯曲......我也必须这样做,并且我估计我可以通过绘制位图来完成此操作。但是,我仍然无法执行任何操作图像部分在Android视图中。)
答
只需使用椭圆形项目值来获得所需的输出。
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/rounded_corner"
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>
我afaraid它不能帮助东阳如果我以这种方式设置的底部,那我该怎么suppos附加一个弯曲的图像到它的底部?就像在上面的图像?视图将仍然有边界 –
对于底部图像只是设置为你的背景r页面,然后在其上添加页眉布局。由于这个原因,你不需要整理你的底部图像。这对你有意义吗? –
这是一个好点,但图像的一些部分,然后将丢失......主要是顶部...... –