Я пытаюсь создать макет с помощью ConstraintLayout с закругленными углами внутри ScrollView. В верхней части макета я хочу разместить изображение, верхние углы которого должны быть закруглены (чтобы соответствовать углам макета), а нижние углы прямые.
Следуя предложениям, которые я нашел в этом вопросе StackOverflow, вот мой код:
<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"
tools:context=".MainActivity"
android:orientation="vertical">
<ScrollView
android:id="@+id/scroll_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_weight="7.5"
android:background="@color/darkModePrimary">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:layout_width="match_parent"
android:background="@drawable/layout_bg"
android:layout_height="wrap_content">
<ImageView
android:background="@drawable/layout_bg"
android:src="@drawable/house_medium"
android:id="@+id/house_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:layout_marginTop="32dp"
android:gravity="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/house_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some text"
android:textSize="24sp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
Это файл xml, в котором я определяю форму фона ConstraintLayout.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/white"/>
<corners android:radius="10dp"/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
Если я установлю эту фигуру в качестве фона как для Constraint Layout, так и для ImageView, я получу, как и ожидалось, изображение со всеми четырьмя закругленными углами, как показано здесь.
Я попытался создать другую форму для использования в качестве фона изображения, например:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/white"/>
<corners android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"/>
</shape>
Но когда я устанавливаю его в качестве фона ImageView, я не получаю то, что хочу, все четыре угла изображения теперь прямые.
Что я делаю неправильно?