Android Shape 详细使用(1)

  • stroke:是描边属性,可以定义描边的 宽度颜色虚实线 等。
<?xml version="1.0" encoding="utf-8"?>

<stroke

android:width=“1dp” // 描边的宽度

android:color=“#ff0000” // 描边的颜色

// 以下两个属性设置虚线

android:dashWidth=“1dp” // 虚线的宽度,值为0时是实线

android:dashGap=“1dp” /> // 虚线的间隔

  • padding:用来定义内部边距。
<?xml version="1.0" encoding="utf-8"?>

<padding

android:left=“10dp” // 左内边距;

android:top=“10dp” // 上内边距;

android:right=“10dp” // 右内边距;

android:bottom=“10dp” /> // 下内边距。

  • size:用来定义图形的大小的。
<?xml version="1.0" encoding="utf-8"?>

<size

android:width=“50dp” // 宽度

android:height=“50dp” /> // 高度

三、特殊属性


  • Shape 特殊属性可以定义当前 Shape 的形状,比如 矩形椭圆形线形环形 … 这些都是通过 Shape 标签属性。
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android=“http://schemas.android.com/apk/res/android”

android:shape=[“rectangle” | “oval” | “line” | “ring”] // Shape 的形状,默认为矩形,可以设置为矩形(rectangle)、椭圆形(oval)、线性形状(line)、环形(ring)

// 下面的属性只有在 android:shape=“ring” 时可用:

android:innerRadius=“10dp” // 内环的半径

android:innerRadiusRatio=“2” // 浮点型,以环的宽度比率来表示内环的半径

android:thickness=“3dp” // 环的厚度

android:thicknessRatio=“2” // 浮点型,以环的宽度比率来表示环的厚度

android:useLevel=“false”> // boolean 值,如果当做是 LevelListDrawable 使用时值为 true,否则为 false。

  • rectangle:矩形
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android=“http://schemas.android.com/apk/res/android”

android:shape=“rectangle”>

  • oval:椭圆
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android=“http://schemas.android.com/apk/res/android”

android:shape=“oval”>

  • line:线
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android=“http://schemas.android.com/apk/res/android”

android:shape=“line”>

<stroke

android:width=“1dp”

android:color=“@color/colorAccent”

android:dashGap=“3dp” // 虚线间距

android:dashWidth=“4dp” /> // 虚线宽度

  • ring:圆环
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android=“http://schemas.android.com/apk/res/android”

android:shape=“ring”

android:useLevel=“false”

android:innerRadius=“20dp” // 内环的半径

android:thickness=“10dp”> // 圆环宽度

四、使用


  • Shape 文件新建在 res/drawable 文件夹下,例如 shape_text.xml

image.png

image.png

image.png

  • shape_text.xml
<?xml version="1.0" encoding="utf-8"?>

<gradient

android:angle=“90”

android:endColor=“#fcf”

android:startColor=“#cff”/>

<padding

android:left=“20dp”

android:top=“20dp”

android:right=“20dp”

android:bottom=“20dp”/>

  • 布局中使用
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“.MainActivity”>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”

android:gravity=“center”>

<TextView

android:id=“@+id/dzm”

android:layout_width=“300dp”

android:layout_height=“300dp”

android:text=“@string/app_name”

android:textSize=“50sp”

android:background=“@drawable/shape_text” />

最后

一线互联网Android面试题含详解(初级到高级专题)

这些题目是今年群友去腾讯、百度、小米、乐视、美团、58、猎豹、360、新浪、搜狐等一线互联网公司面试被问到的题目。并且大多数都整理了答案,熟悉这些知识点会大大增加通过前两轮技术面试的几率

如果设置门槛,很多开发者朋友会因此错过这套高级架构资料,错过提升成为架构师的可能。这就失去了我们的初衷;让更多人都能通过高效高质量的学习,提升自己的技术和格局,升职加薪。

最后送给大家一句话,望共勉,永远不要放弃自己的梦想和追求;

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

、360、新浪、搜狐等一线互联网公司面试被问到的题目。并且大多数都整理了答案,熟悉这些知识点会大大增加通过前两轮技术面试的几率

[外链图片转存中…(img-oGT4aEpq-1714128119954)]

如果设置门槛,很多开发者朋友会因此错过这套高级架构资料,错过提升成为架构师的可能。这就失去了我们的初衷;让更多人都能通过高效高质量的学习,提升自己的技术和格局,升职加薪。

最后送给大家一句话,望共勉,永远不要放弃自己的梦想和追求;

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值