Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angle attribute in android gradient

I am going through test example. Where for some Image background they are using gradient, the code goes like this

<?xml version="1.0" encoding="utf-8"?>     <shape xmlns:android="http://schemas.android.com/apk/res/android">     <gradient         android:startColor="#ff0000"         android:centerColor="#00ff00"         android:endColor="#0000ff"         android:angle="180"/>     <corners android:radius="5dp" />    </shape> 

In the above xml I didn't get angle attribute. but when I change the value of angle slightly the pattern slants. Can anyone explain me how exactly it works?

like image 967
Sharanabasu Angadi Avatar asked Aug 28 '12 06:08

Sharanabasu Angadi


People also ask

What is angle in gradient Android?

attributes: android:angle Integer. The angle for the gradient, in degrees. 0 is left to right, 90 is bottom to top. It must be a multiple of 45.

What is angle gradient?

The grade (also called slope, incline, gradient, mainfall, pitch or rise) of a physical feature, landform or constructed line refers to the tangent of the angle of that surface to the horizontal. It is a special case of the slope, where zero indicates horizontality.

What is Android angle?

ANGLE (Almost Native Graphics Layer Engine) is an open source, cross-platform graphics engine abstraction layer developed by Google. ANGLE translates OpenGL ES 2/3 calls to DirectX 9, 11, OpenGL or Vulkan API calls. It's a portable version of OpenGL but with limitations of OpenGL ES standard. ANGLE. Developer(s)

How do you make a gradient on Android?

To create a gradient color we need to create a . xml file in the drawable folder. So go to app -> res -> drawable and right-click on drawable -> New -> Drawable Resource File and create gradient_drawable.


1 Answers

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:
enter image description here

Here the figure shows the color variation in horizontal direction (angle is set 0).
XML code:

    <shape xmlns:android="http://schemas.android.com/apk/res/android">     <gradient         android:startColor="#000000"         android:angle="0"/>    </shape> 

enter image description here

Here the figure shows the color variation in vertical direction (angle is set 90).
XML code:

<shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient     android:startColor="#000000"     android:angle="90"/>  </shape> 

You can also use different color as start, center and end colors. The code you attached contains all these elements.

like image 74
karn Avatar answered Sep 28 '22 02:09

karn