0

when creating a background with a gradient, it is possible to set the gradient in multiplications of 45

how can I set the gradient angle to 60 for instance?

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape>
        <gradient
            android:angle="45"
            android:startColor="@color/gradient_bottom"
            android:endColor="@color/gradient_top"
            android:type="linear" />
    </shape>
</item>
</selector>
Phantômaxx
  • 36,442
  • 21
  • 78
  • 108
BennyP
  • 1,057
  • 1
  • 12
  • 19

1 Answers1

0

You can use like this.

 <shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
  >
   <gradient
      android:startColor="@color/purple"
       android:endColor="@color/pink"
       android:angle="60" />
 </shape>

If you use shape then it's working fine.

Maraj Hussain
  • 1,378
  • 8
  • 23
  • 1
    thanks for the answer, however it doesn't work. when i put it as a background I get an exception: InflateException: Binary XML file line #8: Binary XML file line #2: Error inflating class. When i change back to 45 it works well. also android studio presents me the shape when it is with 45 and doesn't when it is 60 – BennyP Nov 24 '17 at 16:07
  • also it is explained here:https://stackoverflow.com/questions/12153890/angle-attribute-in-android-gradient. is it possible in another way ? – BennyP Nov 24 '17 at 16:10