【Shape】Shape –形状

1、Shape的初步认识

使用 :android:background=”@drawable/shape”
这种形式来添加控件的背景效果
注意:shape只是改变了控件背景的形状而并没有改变控件的形状
要改变控件的形状需要使用自定义控件来重新绘制控件。
虽然不能改变控件的形状,但是在某些情况下还是可以直接应用shape进行操作,例如使用纯色控件(不加载图片)时。

2、Shape的简单使用

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

通过shape来指定背景的形状
这里可以指定 line(线)、oval(圆)、rectangle(长方形)、ring(圆环)

Shape子项属性介绍:
Corners:背景形状的几个角的弯度
gradient:设置背景形状的颜色 渐变色
solid:设置背景形状的颜色 纯色 – solid和gradient只一个生效
padding:设置间隔
stroke:设置边线颜色
size:形状的大小

3、demo

Xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/iv_circle_header"
       android:layout_margin="30dp"
        android:layout_width="200dp"
        android:text="shape"
        android:gravity="center"
        android:textSize="22sp"
        android:layout_height="200dp"
        android:background="@drawable/shape_rectangle”

</LinearLayout>

Shape_rectangle:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="5dp"/>
    <solid android:color="#00ffff"/>
    <stroke android:width="1dp" android:color="#8000"/>
</shape>

直接可以再xml layout 里面预览到效果
效果图:

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值