About Android shape gradient background gradient

After Baidu, I found that the gradient color can not only be realized according to xml, but also can be realized by java code. Since there is not so much time at present, only the method realized by xml is recorded; in the future, the code realized by Java will be recorded.


Implemented through Shape gradient tags

First look at all the gradient properties of the gradient tag:

<gradient
        android:angle="integer"
        android:centerX="integer"
        android:centerY="integer"
        android:centerColor="integer"
        android:endColor="color"
        android:gradientRadius="integer"
        android:startColor="color"
        android:type=["linear" | "radial" | "sweep"]
        android:useLevel=["true" | "false"] />

attributes:

  • android:angle Integer, representing the angle of the gradient color, 0 is left to right, 90 is bottom to top. Must be an integer multiple of 45. The default is 0. This property only works when type=linear, the default type is linear.
  • android:startColor Color. The start color of the color gradient
  • android:endColor Color. The end color of the color gradient
  • android:centerColor Color. The middle color of the color gradient, mainly used for colorful.
  • android:centerX Float.(0 - 1.0) The gradient position relative to X.
  • android:centerY Float.(0 - 1.0) Relative Y gradient position.
    centerX and centerY, these two properties only work when the type is not linear.
  • android:gradientRadius Float. The radius of the gradient color, the unit should be pixels. Requires android:type="radial". If android:type="radial" is not set, an error will be reported, error inflating class.
  • android:type |Value|Description| |:-|:-| |"linear"| Linear gradient. | |"radial"|A radial gradient. A circular gradient, the starting color starts from the cenralX, centralY point. | |"sweep"|A sweeping line gradient. |

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325824517&siteId=291194637