Skip to content Skip to sidebar Skip to footer

To Draw Rounded Rectangle In Android

I have found this question and the solution was this code :

Solution 1:

I think you couldn't see the rounded rectangle as the radii are small so that they might not be noticed, try to set larger values for the four corners

Here is 120dp radii

<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><solidandroid:color="#ffffff" /><cornersandroid:bottomLeftRadius="120dp"android:bottomRightRadius="120dp"android:topLeftRadius="120dp"android:topRightRadius="120dp" /></shape>

enter image description here

UPDATE

EDIT 2 : The error is now : The following classes could not be found: - corners (Fix Build Path, Edit XML) - shape (Fix Build Path, Edit XML) - solid (Fix Build Path, Edit XML) Tip: Try to build the project.

You can't use drawable tags into xml layout directly like <shape> or layer-list, instead you can refer to drawable resource with some layout view attributes like android:background as below

<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/black"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/test"android:padding="8dp"android:text="Hello World!"android:textColor="@android:color/holo_blue_dark"android:textSize="22sp"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

Post a Comment for "To Draw Rounded Rectangle In Android"