android - android渐变中的角度属性

标签 android android-layout gradient android-shape

我正在通过测试示例。对于某些图像背景,他们在哪里使用渐变, 代码是这样的

<?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 的值时,模式会倾斜。谁能解释一下它是如何工作的?

最佳答案

梯度基本上表示任何量的空间(方向)变化。用颜色表示颜色强度在以角度表示的方向上的变化。这里有一些图表来表示这个概念:
enter image description here

下图是水平方向的颜色变化(角度设置为0)。
XML代码:

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

enter image description here

下图为垂直方向的颜色变化(角度设置为90)。
XML代码:

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

您还可以使用不同的颜色作为开始、中心和结束颜色。您附加的代码包含所有这些元素。

关于android - android渐变中的角度属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12153890/

相关文章:

java - Android WebView 在转动智能手机时加载起始页

Android ArcGIS - 触摸标记时显示弹出窗口

android - 在我的自定义 View 上读取 Android 属性

css - 对 Angular 渐变和替代品中的平滑线

jquery - 渐变文本跨浏览器

java - 单击自定义 ListView 的项目时如何启动新 Activity

android - 服务/后台进程中的相机帧

javafx - 使用 JavaFX 将渐变应用于球体对象

android - 如何更改Android中数字选择器的背景颜色

android - 显示为正方形的 float 操作按钮