Payal
Payal

Reputation: 913

How to implement opposite gradient in android?

I am using this

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <corners android:radius="7sp" />
        <gradient
            android:startColor="#333"
            android:centerColor="#ffffff"
            android:endColor="#333"
            android:angle="90" />

            <stroke android:width="1dp" android:color="#FFffffff" />
    </shape>
</item>

But this does not give the desired effect.

enter image description here

Upvotes: 0

Views: 163

Answers (4)

Murtaza Khursheed Hussain
Murtaza Khursheed Hussain

Reputation: 15336

You can try it this way

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@drawable/gradient"
        android:orientation="vertical" >
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/gradient2"
        android:orientation="vertical" >
    </RelativeLayout>

</RelativeLayout>

Gradient 1

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >
            <corners android:radius="7sp" />

            <gradient
                android:angle="90"
                android:endColor="#D1D1D1"
                android:startColor="#000" />

            <stroke
                android:width="1dp"
                android:color="#FFffffff" />
        </shape>
    </item>

</layer-list>

Gradient 2

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >
            <corners android:radius="7sp" />

            <gradient
                android:angle="90"
                android:endColor="#000"
                android:startColor="#D1D1D1" />

            <stroke
                android:width="1dp"
                android:color="#FFffffff" />
        </shape>
    </item>

</layer-list>

Final Result

enter image description here

Upvotes: 2

Piyush
Piyush

Reputation: 18923

Use :

<shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="rectangle" >
 <gradient 
   android:type="linear"
   android:centerX="50%" 
   android:startColor="#FFc0c0c0" 
   android:centerColor="#FFffffff" 
   android:endColor="#FF808080" 
   android:angle="270"/>
</shape>

<corners android:radius="7sp" />

Upvotes: 0

Maveňツ
Maveňツ

Reputation: 1

Try

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape>
        <gradient
            android:startColor="#4C4C43"
            android:centerColor="#B8B894"
            android:endColor="#4C4C43"
            android:angle="270" />
    </shape>
</item>

enter image description here

P.S - change color according to your need

reference- http://www.learn-android-easily.com/2013/06/gradient-drawable-in-android.html

Upvotes: 1

Saeed Masoumi
Saeed Masoumi

Reputation: 8916

Use this instead

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <gradient
                android:startColor="#333"
                android:centerColor="#DDD"
                android:endColor="#333"
                android:angle="90" />

                <stroke android:width="1dp" android:color="#FF333333" />
        </shape>
    </item>
    <item android:left="4dp" android:right="4dp" android:top="1dp" android:bottom="1dp">
        <shape android:shape="rectangle">
            <gradient
                android:startColor="#AAA"
                android:centerColor="#FFF"
                android:endColor="#AAA"
                android:angle="90" />
        </shape>
    </item>
</layer-list>

But it's better to use nine-patch images

Upvotes: 1

Related Questions