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="">
    <corners android:radius="5dp" />

in the above xml I didn’t get angle attribute. but when i change the value of angle slightly the pattern slants . can any one explain me how exactly it works……….. 🙂

  • difference between methods to scale a bitmap
  • Adding a button to the ActionBar with ActionBarSherlock
  • CoordinatorLayout with two floating action buttons
  • Android Eclipse Classpath - want to add classpath container path but eclipse won't let me
  • Taking screenshot of Android OpenGL
  • Set alpha-transparency only to layout and not to it's children
  • Related posts:

    Android Studio installation on Windows 7 fails, no JDK found
    View outside bounds not drawing properly
    Use of dispatchDraw(Canvas canvas)
    Automatically clearing LogCat on each Eclipse Debug/Run?
    when is Snackbar isQueued () used? (How to queue the snackbar)
    Background image dimension for Navigation Drawer header
  • Eclipse Android SDK - error in building workspace
  • How to set gradient style to paint object?
  • Android:add helvetica neue font in application
  • Android NDK: No rule to make target
  • Difference between task and process in Android
  • NoSuchMethodError if i am using okhttp 2.0 and the latest retrofit?
  • 3 Solutions collect form web for “angle attribute in android gradient”

    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="">

    enter image description here

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

    <shape xmlns:android="">

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

    Specifies a gradient color for the shape.

    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. Default is 0.

    It seems that the description in the document is contradict to karn’s answer??

    You can find more details in this page。

    you might wanna create diagonal gradient from code. It’s much easier and you have a lot of options open from there. This snippet helped me

    public void SetGradient(View view) {
            GradientDrawable gd = new GradientDrawable(
                    new int[]{0xFF141a24, 0xFF293f49, 0xFF72554c});

    available directions from GradientDrawable class

    /*public enum Orientation {
            *//** draw the gradient from the top to the bottom *//*
            *//** draw the gradient from the top-right to the bottom-left *//*
            *//** draw the gradient from the right to the left *//*
            *//** draw the gradient from the bottom-right to the top-left *//*
            *//** draw the gradient from the bottom to the top *//*
            *//** draw the gradient from the bottom-left to the top-right *//*
            *//** draw the gradient from the left to the right *//*
            *//** draw the gradient from the top-left to the bottom-right *//*

    and you call the method from onCreate or onCreateView in fragment and pass parent view(in my case).

        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.dialog_view_parent, container);           
            return view;
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.