如何在Android形状中创建带有负圆角的矩形

问题描述 投票:0回答:1

我正在尝试创建此形状,但是我完全堆叠在其中。关于如何创建它有任何想法吗?

请注意 Lorem ipsum是一幅图像,它不是恒定的。并且lorem ipsum的Image视图在ScrollView内,并且还有其他元素。因此我需要以某种方式使滚动视图的角变为圆形

enter image description here

这是我的XML代码:


<androidx.constraintlayout.widget.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/blue"
    tools:context=".event.EventFragment">

    <LinearLayout
        app:layout_constraintTop_toTopOf="parent"
        android:id="@+id/topTollbar"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp">
        <Button
            android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>


    <ScrollView
        android:layout_marginBottom="55dp"
        android:layout_marginTop="60dp"
        android:background="@color/white"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <LinearLayout
        android:layout_marginStart="5dp"
        android:layout_marginEnd="5dp"
        android:id="@+id/back_place"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="60dp"
        android:layout_marginBottom="60dp"
        android:orientation="vertical">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="300dp"/>
        <TextView
            android:text="@string/archive"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="300dp"/>
    </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
android android-custom-view shapes
1个回答
0
投票

为该背景制作自己的形状文件。

例如shape.xml中的>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/color_222222" />
            <stroke
                android:width="0.5dp"
                android:color="@color/color_222222"/>
            <size android:height="36dp" />
            <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" android:topLeftRadius="80dp" android:topRightRadius="80dp" />
        </shape>
   <item android:drawable="@drawable/iamge_file_as_you_want" />
</layer-list>

iamge_file_as_you_want可以做出很多解决。

并根据需要使用背景。这样。

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/shape" />
© www.soinside.com 2019 - 2024. All rights reserved.