4

rectangle shape

how can I create rectangle shape by using two different colors with shadow? like above image.

Prithiv Dharmaraj
  • 357
  • 2
  • 4
  • 17

4 Answers4

8
Please create a drawable file and put the below code in it.

    <?xml version="1.0" encoding="utf-8"?>
        <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
            <item>
                <shape android:shape="rectangle" >
                    <size android:height="20dp" />
                    <solid android:color="#F66D08" />
                </shape>
            </item>
            <item android:top="50dp">
                <shape android:shape="rectangle" >
                    <gradient android:endColor="#AD1B1D"
                        android:startColor="#E2360A"
                        android:angle="270" />
                </shape>
            </item>
        </layer-list>
7

layer-list can be used to solve this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="rectangle">
            <size
                android:width="40dp"
                android:height="40dp" />
            <solid android:color="#F86F05" />
        </shape>
    </item>

    <item android:top="10dp">
        <shape android:shape="rectangle">
            <size
                android:width="30dp"
                android:height="30dp" />
            <solid android:color="#B31F19" />
        </shape>
    </item>

</layer-list>

And the screenshot of the same.

enter image description here

If you want gradient instead of solid color, change solid to gradient and set startColor, endColor and angle.

capt.swag
  • 10,335
  • 2
  • 41
  • 41
1

enter image description herePlace these code in your activity_main :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:gravity="center"
        android:background="#F66D08"
        android:layout_width="match_parent"
        android:layout_height="20dp">

    </LinearLayout>

    <LinearLayout
        android:background="@drawable/introslidergradiant"
        android:layout_width="match_parent"
        android:layout_height="100dp"></LinearLayout>
</LinearLayout>

And create drawble res file with introslidergradiant.xml name :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:angle="90"
                android:startColor="#A31720"
                android:endColor="#E1350B"
                android:type="linear" />
        </shape>
    </item>
</selector>
0

You have to make a xml file in the drawable

<shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle" >
<gradient
android:type="linear"
android:startColor="#FFFF820D"
android:endColor="#FFA32815"
android:angle="90"/>
</shape>

use the following code or you can generate your own gradient here just set the color and select the android option and it will generate the gradient for you .

Neelay Srivastava
  • 1,041
  • 3
  • 15
  • 46