Android渐变中的angle属性 [英] angle attribute in android gradient

查看:745
本文介绍了Android渐变中的angle属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过测试示例。他们在使用渐变的某些图片背景中,
代码如下所示

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>

在上面的xml中,我没有得到 angle 属性。但是当我更改 angle 的值时,图案会稍微倾斜。谁能解释我到底是如何工作的?

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?

推荐答案

梯度基本上表示任何数量的空间(方向)的变化。对于颜色,它表示颜色强度在角度表示的方向上的变化。以下是代表此概念的一些图表:

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:

此处该图显示了水平方向上的颜色变化(角度设置为0)。
XML代码:

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>

此处该图显示了垂直方向的颜色变化(角度设置为90)。
XML代码:

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.

这篇关于Android渐变中的angle属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆