I applied a gradient drawable resource as a background for a view.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
<gradient
android:startColor="#cf2aff"
android:endColor="#5409ff"
android:type="linear" />
</shape>
In devices with Android version < 10
it is shown as expected:
But in devices with Android 10
it is rotated 90 degrees:
Did anyone have the same problem and know how to fix it?
The value of the centerX and centerY attributes is a relative position defined as a Float value ranging from 0 to 1.0. The angle of the gradient can be set using the android:angle attribute using the Integer value representing the angle in degrees. This value must be a multiple of 45.
Gradient basically represents the variation in space(in a direction) of any quantity. With color it represents the variation of color intensity in a direction represented by angle. Here are some diagrams to represent this concept: Here the figure shows the color variation in horizontal direction (angle is set 0).
type="linear"Set the angle for a linear type. It must be a multiple of 45 degrees.
Add android:angle="0"
I got a fix for this. You need to set android:angle
attribute even if it is 0 to make it work on Android 10.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
<gradient
android:angle="0"
android:startColor="#cf2aff"
android:endColor="#5409ff"
android:type="linear" />
</shape>
I suppose for Android 10, angle is set to 90 degrees by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With