3

I would like to make an XMl drawable file that resembles as closely as possible to the material design elevation found on Lollipop and above. I currently have a shadow that does not even come close as I have no idea what gradient I'm suppose to use. enter image description here

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <gradient android:angle="90"
            android:endColor="@android:color/darker_gray" 
            android:startColor="#ccc" />
        <corners android:radius="0.1dp"
            android:bottomLeftRadius="3dp"
            android:bottomRightRadius="3dp"
            android:topLeftRadius="3dp"
            android:topRightRadius="3dp"/>
    </shape>
</item>
<item
    android:left="1.5dp"
    android:right="1.5dp"
    android:top="1.5dp"
    android:bottom="1.5dp">

    <shape android:shape="rectangle">

<solid android:color="@android:color/white" />

<corners
    android:radius="0.1dp"
    android:bottomLeftRadius="3dp"
    android:bottomRightRadius="3dp"
    android:topLeftRadius="3dp"
    android:topRightRadius="3dp" />
</shape>
</item>
</layer-list>

Can someone come up with a solution that is at least better than mine? Thank you.

Maveňツ
  • 1
  • 12
  • 50
  • 89
Lord Goderick
  • 965
  • 2
  • 14
  • 32

2 Answers2

0

You need to define elevation in you layout resource file to drop shadow. in your layout.xml file it should look something like this

<TextView
    android:id="@+id/myview"
    android:elevation="2dp"
    android:background="@drawable/myrect" />
nandish
  • 41
  • 4
0

For perfect shadow use CardView

Xamarin: MSDN Source

To add the Xamarin.Android.Support.v7.CardView package in Visual Studio

<android.support.v7.widget.CardView
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:local="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="@dimen/shrine_grid_item_margin"
          android:orientation="vertical"
          local:cardElevation="@dimen/cardview_default_elevation">
<!-- Content Goes here-->
</android.support.v7.widget.CardView>

Or

Android: Android Devs Source

The CardView widget is part of the v7 Support Libraries. To use it in your project, add the following dependency to your app module's build.gradle file:

dependencies {
    implementation 'com.android.support:cardview-v7:28.0.0'
}

XXX

<androidx.cardview.widget.CardView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/ProductEntry"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_margin="@dimen/shrine_grid_item_margin"
  android:orientation="vertical"
  app:cardElevation="@dimen/cardview_default_elevation">
<!-- Content Goes here-->
</androidx.cardview.widget.CardView>
PsyhoLord
  • 69
  • 1
  • 3