• Android背景渐变色(shape,gradient)


    Android设置背景色可以通过在res/drawable里定义一个xml,如下:

    <?xml version="1.0" encoding="utf-8"?>
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape=["rectangle" | "oval" | "line" | "ring"] >   --- 默认为rectangle
        <corners  -- shape=“rectangle”时使用, 
            android:radius="integer"  -- 半径,会被下边的属性覆盖,默认为1dp,
            android:topLeftRadius="integer" 
            android:topRightRadius="integer"
            android:bottomLeftRadius="integer"
            android:bottomRightRadius="integer" />
        <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"] />
        <padding
            android:left="integer"
            android:top="integer"
            android:right="integer"
            android:bottom="integer" />
        <size    -- 指定大小,一般用在imageview配合scaleType属性使用。大小一般会适配滴
            android:width="integer"
            android:height="integer" />
        <solid    -- 填充颜色,可是是十六进制颜色。(比如想设置半透明效果,直接使用十六就只就OK)
            android:color="color" />
        <stroke    -- 指定边框,border,dashWidth和dashGap有一个为0dp则为
            android:width="integer"
            android:color="color"
            android:dashWidth="integer"    -- 虚线宽度
            android:dashGap="integer" />    -- 虚线间隔宽度
    </shape>

    shape是用来定义形状的,gradient定义该形状里面为渐变色填充,startColor起始颜色,endColor结束颜色,angle表示方向角度。当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。

    实现过程:

    https://blog.csdn.net/qq_22605739/article/details/47441059

  • 相关阅读:
    PHP
    PHP
    PHP
    网站页面引导操作
    Solr与Tomcat的整合
    POI操作文档内容
    HashTable和HashMap的区别
    ArrayList、LinkedList、HashMap底层实现
    正则表达式语法
    Java并发编程:线程间通信wait、notify
  • 原文地址:https://www.cnblogs.com/wcLT/p/8821506.html
Copyright © 2020-2023  润新知