shape绘制形状基础详细解析

本文详细介绍了Android中shape的使用,包括定义XML资源文件、四种基本形状(line、oval、rectangle、ring)以及常见属性如stroke。还讨论了圆角shape、下划线虚线的绘制问题,并提到了Android 3.0后硬件加速对虚线显示的影响及解决办法。
摘要由CSDN通过智能技术生成

在这里插入图片描述

android 的样式主要则是通过 shape、selector、layer-list、level-list、style、theme、layer、bitmap 等组合实现
这篇文章主要介绍最基础的形状定义工具shape

1.Android develelopers官方解释
Defines a generic graphical “shape.”

Any Shape can be drawn to a Canvas with its own draw() method, but more graphical control is available if you instead pass it to a ShapeDrawable.

Custom Shape classes must implement clone() and return an instance of the custom Shape class.
翻译:定义通用图形“形状”。
任何形状都可以通过它自己的draw()方法绘制到画布上,但如果你把它传递给一个ShapeDrawable,就可以使用更多的图形控件。
自定义Shape类必须实现clone()并返回自定义Shape类的一个实例。
2.定义与使用shape
2.1定义shape
定义Shape需要在res/drawable/目录下建一个XML资源文件
在这里插入图片描述
2.2使用shape

 <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/shape"
        android:src="@drawable/shape"/>

一般通过设置background和src依靠layout布局中控件进行引用,把定义好的Shape设置为背景。因为APP界面中的元素,都是通过控件进行展示的,形状也是一种绘图元素,必须依附于控件。
3.Shape一共支持四种形状
在这里插入图片描述
①line : 线形,可以画实线或者虚线

②oval : 椭圆形,可以画正圆或者椭圆

③rectangle : 矩形,默认的形状,可以画出直角矩形、圆角矩形、弧形等

④ring : 环形,可以画环形进度条
4.属性介绍

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

橘子先生z

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值