0
votes

I have been trying to create a list-view item custom background resource in order to create a shadow effect to my items. Only problem is I'm stuck with these annoying black corners (see image below). I'm not using 'radius' attribute anywhere and I've assigned background color white to all relevant items surrounding my list-view item. Don't know where these black corners are coming from. Following my xml code for the item:

    <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!--shadow to bottom and right-->
    <!--by pushing offset from top and left-->
    <item
        android:left="0dp"
        android:right="2dp"
        android:top="2dp"
        android:bottom="0dp">
        <shape
            android:shape="rectangle">
            <solid android:color="@android:color/darker_gray" />
        </shape>
    </item>
    <!--foreground-color to cover over non-shadow-->
    <!--need to also offset in opposite direction-->
    <item
        android:left="2dp"
        android:right="0dp"
        android:top="0dp"
        android:bottom="2dp">
        <shape
            android:shape="rectangle">
            <solid android:color="@android:color/white"/>
        </shape>
    </item>
</layer-list>

Black corners, exactly matching offsets in xml resource

1

1 Answers

0
votes

You can either use help from this link https://developer.android.com/training/material/shadows-clipping.html or you can use CardView for this purpose:

compile 'com.android.support:cardview-v7:26.0.0'

        <android.support.v7.widget.CardView
         android:id="@+id/card_view"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:cardCornerRadius="2dp"
         app:cardElevation="2dp"
         app:cardPreventCornerOverlap="false"
         app:contentPadding="0dp">

        <!-- add you views or other stuff here -->

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