Puspam
Puspam

Reputation: 2777

How to set a gradient angle?

I know that there are many answers to this question, but I am looking for something different.

I know that by creating a gradient in xml, we can set the angle, but it should be a multiple of 45. Also, I know that there are no methods in the GradientDrawable class to set the angle.

So, my question is that how to set a custom angle of a gradient in android platform ? I want to set a custom gradient angle which may not be a multiple of 45.

Upvotes: 0

Views: 538

Answers (1)

Ankit Tale
Ankit Tale

Reputation: 2004

Here is how you can set angle in the background with this drawable code. But for that angle on the background, I will suggest a different way.

Way 1:

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

    <item>
        <shape android:shape="rectangle">
            <solid android:color="#43CEE0"/>
        </shape>
    </item>

    <item
        android:bottom="-100dp"
        android:left="0dp"
        android:right="-260dp"
        android:top="270dp">
        <rotate
            android:fromDegrees="-10"
            android:pivotX="0%"
            android:pivotY="100%">
            <shape
                android:shape="rectangle">
                <solid
                    android:color="@android:color/white"/>
            </shape>
        </rotate>
    </item>
</layer-list>

Using this you can set the angle between view. But the angle will get disturbed on a different screen. When I use this on a big screen phone it simply not work effectively.

Another way is to get an image developed by the designer and set to the background. mdpi to xxxhdpi. In Android, you can refer above view to create an image.

Upvotes: 1

Related Questions