Avada Kedavra Avada Kedavra - 1 month ago 10
Android Question

How to set corner radius for cardview with some child members?

The 1st image is my result and i want to make to look like the 2nd one. I have tried to make to give corner radius but it didn't appear in the screen. I don't know what's the problem and also the elevation doesn't appear to the parent cardview.

Thankyou in advance.

enter image description here

enter image description here

<RelativeLayout 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="#ffffff"
tools:context="com.software_solutions.optimus_tech_project201709.CourseSelect.CourseSelectionActivity">

<Button
android:id="@+id/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Register" />


<Button
android:id="@+id/you"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="you" />

<ImageView
android:id="@+id/dialogImageView"
android:layout_width="match_parent"
android:layout_height="220dp"
android:scaleType="fitXY"
android:src="@drawable/dialog"
android:text="Hello" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/dialogImageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="-180dp"
android:gravity="center"
android:orientation="vertical">

<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/select_course" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="SELECT A COURSE"
android:textColor="#ffffff"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/dialogImageView"
android:orientation="vertical"
android:weightSum="2">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewSelectCourse"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp" />


<android.support.v7.widget.CardView
android:id="@+id/cardViewDemo1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:elevation="3dp"
app:cardCornerRadius="10dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e4a455"
android:orientation="vertical"
android:padding="10dp"
android:weightSum="3">

<android.support.v7.widget.CardView
android:id="@+id/cardViewDemo2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:cardCornerRadius="10dp">

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/demo_one" />

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/cardViewDemo3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/cardViewDemo2"
android:layout_marginTop="5dp"
android:layout_weight="2"
app:cardCornerRadius="10dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e9cca8">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="DEMOVIDEOONE"
android:textColor="#fff"
android:textSize="15sp"
android:textStyle="bold" />

</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>


</android.support.v7.widget.CardView>

</LinearLayout>

</RelativeLayout>

Answer Source

Add app:cardBackgroundColor="#e9cca8" app:cardBackgroundColor="#e4a455" and remove background from your child RelativeLayout and LinearLayout

You have 3 CardView, in 3rd CardView, you have only ImageView, So better instead of using CardView you can use round corner Image view.