Android shape记录

news/2024/5/17 15:34:55 标签: android, gitee

之前一直觉得dataPath很好用,可以画各种矢量图。今天发现用shape画图也不错,记录一下自己用shape画的图。

一般使用shape就是定义形状、stroke边、solid内部、corners圆角等,代码

<?xml version ="1.0" encoding ="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners
        android:radius="@dimen/dp_10" />
    <solid
        android:color="?attr/colorBgKey" />
    <stroke android:width="@dimen/dp_1" android:color="@color/black"/>
</shape>

然后,shape也可以处理一下复杂一点的。

这其实是画两层,一层是一个渐变圆,一层是是个实心圆。

shape分层就需要用到 layer-list 每一层用 item 包裹,在 item 中写具体的shape。其中item可以指定width、height、top、left、right、bottom来控制每一层的位置。

代码如下

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:width="@dimen/dp_30"
        android:height="@dimen/dp_30">
        <shape android:shape="oval">
            <gradient
                android:centerX="50%"
                android:centerY="50%"
                android:endColor="#00FF0000"
                android:gradientRadius="50%"
                android:startColor="#FFFF0000"
                android:type="radial" />
        </shape>

    </item>
    <item
        android:width="@dimen/dp_10"
        android:height="@dimen/dp_10" android:top="@dimen/dp_10" android:left="@dimen/dp_10">
        <shape android:shape="oval">
            <solid android:color="#FFFF0000"/>
        </shape>
    </item>
</layer-list>

下面是一个拍照背景图片

也是用到layer-list,代码如下

<?xml version ="1.0" encoding ="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <stroke
                android:width="@dimen/dp_5"
                android:color="?attr/colorBorder"
                android:dashWidth="@dimen/dp_10"
                android:dashGap="@dimen/dp_10" />
            <corners android:radius="@dimen/dp_15" />
            <solid android:color="?attr/colorBg" />
        </shape>

    </item>
    <item
        android:left="@dimen/dp_50"
        android:right="@dimen/dp_50">
        <shape android:shape="line">
            <stroke
                android:width="@dimen/dp_5"
                android:color="?attr/colorBorder" />
        </shape>
    </item>
    <item
        android:left="@dimen/dp_50"
        android:right="@dimen/dp_50">
        <rotate android:fromDegrees="90">
            <shape android:shape="line">
                <stroke
                    android:width="@dimen/dp_5"
                    android:color="?attr/colorBorder" />

            </shape>
        </rotate>
    </item>
</layer-list>


http://www.niftyadmin.cn/n/5056719.html

相关文章

DevSecOps 将会嵌入 DevOps

通常人们在一个项目行将结束时才会考虑到安全&#xff0c;这么做会导致很多问题&#xff1b;将安全融入到DevOps的工作流中已产生了积极结果。 DevSecOps&#xff1a;安全正当时 一直以来&#xff0c;开发人员在构建软件时认为功能需求优先于安全。虽然安全编码实践起着重要作…

游戏设计模式专栏(一):工厂方法模式

引言 大家好&#xff0c;我是亿元程序员&#xff0c;一位有着8年游戏行业经验的主程。 本系列是《和8年游戏主程一起学习设计模式》&#xff0c;让糟糕的代码在潜移默化中升华&#xff0c;欢迎大家关注分享收藏订阅。 在游戏开发中&#xff0c;代码的组织和结构对于项目的可…

05-前端基础CSS第三天

01-CSS三大特性之层叠性 1.CSS的三大特性 CSS有三个非常重要的三个特性&#xff1a;层叠性、继承性、优先级。 1.1 层叠性 相同选择器给设置相同的样式&#xff0c;此时一个样式就会**覆盖&#xff08;层叠&#xff09;**另一个冲突的样式。层叠性主要解决样式冲突的问题。…

IM同步服务

设计概述 后台同步方案的设计就是数据存储结构的设计&#xff0c;如何快速体现“信息变化”&#xff0c;如何快速计算出“变化信息”。后台数据存储结构是由同步协议中同步契约决定的。 设计方案 该方案的同步是按照业务粒度来划分&#xff0c;只需要同步sdk要求同步的数据。…

Redis与分布式-主从复制

接上文 常用中间件-OAuth2 1.主从复制 启动两个redis服务器。 修改第一个服务器地址 修改第二个redis 然后分别启动 redis-server.exe redis.windows.conf) 查看当前服务器的主从状态&#xff0c;打开客户端&#xff1a;输入info replication命令来查看当前的主从状态&am…

【软件测试】开发/测试模型

开发/测试模型 瀑布模型 设计&#xff1a;技术文档(设计那些接口&#xff0c;库表&#xff0c;mq&#xff0c;定时任务)&#xff0c;UI视觉稿 特点&#xff1a;线性的结构。 优点&#xff1a;每个阶段做什么&#xff0c;产出什么非常清晰 缺点&#xff1a;测试人员介入太晚…

蓝桥等考Python组别八级001

第一部分:选择题 1、Python L8 (15分) 运行下面程序的结果是( )。 i = 1 while i < 10: print(i, end= ) i += 1 1 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 9 100 1 2 3 4 5 6 7 8 90 1 2 3 4 5 6 7 8 9 10正确答案:A 2、Python L8 (15分)

Mybatis配置文件(mybatis-config.xml)和Mapper映射文件(XXXMapper.xml)模板

配置文件 ${dirver} ---> com.mysql.jdbc.Driver ${url} ---> jdbc:mysql://localhost:3306/数据库名 <?xml version"1.0" encoding"UTF-8" ?> <!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""h…