0

I need to apply corner radius to a LinearLayout which also has a background for shadow effect. When I try to add corner radius to the background XML I only get white background on the corners. I will demonstrate what I mean with code and photos.

This is the code in the shadow.xml (notice the line with <corners android:radius="30dp"/>):

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--the shadow comes from here-->
<item
    android:bottom="0dp"
    android:drawable="@android:drawable/dialog_holo_light_frame"
    android:left="0dp"
    android:right="0dp"
    android:top="0dp">
</item>

<item
    android:bottom="0dp"
    android:left="0dp"
    android:right="0dp"
    android:top="0dp">
    <!--whatever you want in the background, here i preferred solid white -->
    <shape android:shape="rectangle">
        <solid android:color="@color/myPink" />
        <corners android:radius="30dp"/> //THIS LINE IS NOT INCLUDED IN PHOTO 1
    </shape>
</item>

This is the starting point (without <corners android:radius="30dp"/> in shadow.xml): enter image description here

And this is the result I am getting (with <corners android:radius="30dp"/> in shadow.xml) enter image description here

Now how can the corner radius without the white background on the corners of the Linear Layout?

Peter
  • 1,848
  • 4
  • 26
  • 44

2 Answers2

0

Maybe you should try to add android:color="@android:color/transparent" property to or you can use RelativeLayout and use one ImageView with this property in that layout and also set android:src="@drawable/shadow"

java_brat
  • 72
  • 4
0

You already seem to be doing the right thing, which is to put the LinearLayout inside of a CardView. Just a bit of trick is going to achieve the result.

You do not need to do the background shadow and corner for LinearLayout. Instead, use the CardView as a container and apply background, elevation (for shadow) and radius to the CardView.

codeFood
  • 1,241
  • 16
  • 16