Is there any way to create rounded corners of a View
inside the LinearLayout
instead of using shape
?
<View
android:layout_width="48dp"
android:clickable="true"
android:layout_height="48dp"
android:background="#f55151" />
Is there any way to create rounded corners of a View
inside the LinearLayout
instead of using shape
?
<View
android:layout_width="48dp"
android:clickable="true"
android:layout_height="48dp"
android:background="#f55151" />
You can use a CardView and inside the cardview you can make your own views. On the CardView you can set the card_view:cardCornerRadius.
<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@color/yourColor"
card_view:cardCornerRadius="6dp">
<View
android:layout_width="48dp"
android:clickable="true"
android:layout_height="48dp"
android:background="#f55151" />
</androidx.cardview.widget.CardView>
If you don`t want to use shape CardView is the easiest way: for more detail look at the official docs
first add this line to your dependencies:
implementation 'com.android.support:cardview-v7:28.0.0'
then use it like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
... >
<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
</LinearLayout>
You can find more options here like: corner radius, elevation, background color and so on.