Android Studio属性学习(一)——shape属性

一、前提

在这里会讲解shape属性的各个元素,以及效果展示及使用

二、目标

shape

三、内容

1、首先创建一个shape.xml文件以及在布局文件中添加一个按钮用来展示添加属性后的样式

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

</shape>

在shape中第一个可以添加的要素是android:shape=“”(可选可不选,可以直接在里面添加颜色形状什么的,直接用在控件上)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

</shape>

其中shape中有四个可选要素

android:shape="rectangle"  表示矩形

android:shape="line"           表示线形(一般不怎么用)

android:shape="oval"          表示椭圆

android:shape="ring"           表示圆环

2、就shape里面的元素开讲,拿矩形举例

(1)solid 用于指定内部的填充色,里面的属性只有color一条

<solid android:color="color"/>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="#24e9d2"/>
</shape>

属性展示:      效果展示:  

(2)corners用于指定圆角,里面的属性有5条

<corners android:radius=""/>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="#24e9d2"/>
    <corners android:radius="20dp"/>
</shape>

android:radius="20dp"

所有圆角半径
android:topLeftRadius="20dp" 左上圆角半径
android:topRightRadius="20dp" 右上圆角半径
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值