Android - Layout Rounded Corners
Lets see how to apply rounded corners to layouts in Android.
1. Create an Android project with an empty activity.
2. Create a drawable named rounded_corner_drawable.xml inside drawable resources folder.
3. Add following code into created file.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FF4F79"/>
<corners android:radius="35dp"/>
</shape>4. Open activity layout XML file.
5. Add following layouts into layout file.
<?xml version="1.0" encoding="utf-8"?>
<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=".RoomsActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:background="@drawable/rounded_corner_drawable"/>
</androidx.constraintlayout.widget.ConstraintLayout>6. Result :
We used background property of our layout to apply rounded corner background.
Use radius value in created drawable to change corner radius size.


Comments
Post a Comment