Android studio xml 的属性

本文详细介绍了Android中使用Shape XML进行图形界面设计的方法,包括虚线、椭圆边框、环形和矩形的属性设置,如颜色、宽度、角度等,以及如何通过代码实现这些图形元素。

虚线

属性属性值作用
shapeline设置形状为线型
stroke以下属性设置line的属性
widthinteger线的厚度
colorcolor线的颜色
dashGapinteger每段线的间隔(为0的话就是直线)
dashWidthinteger每段线的长度

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <!--android:width虚线的高度-->
    <!--android:width的值必须要小于用它做背景的View的height-->
    <stroke
        android:width="1dp"
        android:color="#f00"
        android:dashGap="2sp"

        android:dashWidth="10dp" />
</shape>

椭圆边框

属性属性值描述
shapeoval椭圆
stroke设置边框属性在这里插入图片描述
corners角度设置四个角的角度

代码如下:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <stroke
        android:width="2dp"
        android:color="#49da2b"
        android:dashGap="20sp"
        android:dashWidth="18dp" />
    <corners android:radius="10dp"/>
</shape>

环 ring

属性属性值描述
shapering
innerRadiusRatiofloat环内径比(屏幕宽度/半径)
thicknessRatiofloat厚度比(屏幕宽度/厚度)
typesweep渐变
在这里插入图片描述

代码如下:

<?xml version="1.0" encoding="utf-8"?><!--android:useLevel该值设为false,否则会看不到圆环画面-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadiusRatio="4"
    android:shape="ring"
    android:thicknessRatio="4"
    android:useLevel="false">
    <gradient
        android:endColor="#cbd5e1"
        android:startColor="#5adece"
        android:type="sweep" />
</shape>

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetLeft="1.0px"
    android:insetRight="1.0px">
    <selector>
        <item>
            <shape android:shape="rectangle">
                <gradient
                    android:angle="270"
                    android:endColor="#154d91"
                    android:startColor="#24b124" />
                <corners android:radius="10dp" />
                <stroke
                    android:width="5dp"
                    android:color="#0f0" />

            </shape>
        </item>
    </selector>
</inset>

在这里插入图片描述

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值