android studio 创建shape,Android Studio属性学习(一)——shape属性

一、前提

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

二、目标

shape

三、内容

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

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

其中shape中有四个可选要素

android:shape="rectangle"  表示矩形

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

android:shape="oval"          表示椭圆

android:shape="ring"           表示圆环

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

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

属性展示:779f3321307971e571fb29a03eb6a496.png      效果展示:  9fa77eac5defc3d2adefd9b951138fd1.png

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

android:radius="20dp"

所有圆角半径

2f71735b524a09788c72fb52cfd4c2ae.png

8f8e0391b89e8bcd71c3e2c48de7593d.png

android:topLeftRadius="20dp"

左上圆角半径

27fd27767f799189c0c1f769489cb93c.png

android:topRightRadius="20dp"

右上圆角半径

8c639d65d30d6dd6a3602eed8c85cad1.png

android:BottomLeftR

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的四分之三圆弧的ProgressBarView的XML代码示例: ```xml <ProgressBar android:id="@+id/circular_progress_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" android:progressDrawable="@drawable/circular_progress_bar" android:max="100" android:progress="50"/> ``` 其中,android:progressDrawable属性指定了ProgressBar的Drawable,我们需要定义一个drawable资源文件来实现四分之三圆弧的效果,下面是drawable资源文件circular_progress_bar.xml的代码: ```xml <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 圆环背景 --> <item> <shape android:shape="ring" android:innerRadiusRatio="3" android:thicknessRatio="8" android:useLevel="false"> <solid android:color="@color/light_gray"/> </shape> </item> <!-- 圆环进度 --> <item> <rotate android:fromDegrees="270" android:toDegrees="270"> <shape android:shape="ring" android:innerRadiusRatio="3" android:thicknessRatio="8" android:useLevel="true"> <gradient android:type="sweep" android:startColor="@color/red" android:endColor="@color/orange" android:angle="0" android:centerX="0.5" android:centerY="0.5" android:useLevel="true"/> </shape> </rotate> </item> </layer-list> ``` 其中,我们使用了layer-list来定义一个圆环背景和一个圆环进度,圆环背景使用了ring形状,设置了innerRadiusRatio为3,thicknessRatio为8,useLevel为false,实现了一个厚度为8dp,半径为3dp的圆环背景;圆环进度使用了rotate旋转动画,将其从270度开始旋转,结束时还是270度,实现了四分之三圆弧的效果;在圆环进度的shape中使用了sweep类型的gradient,设置了起始颜色和结束颜色,并将其角度设置为0,中心点设置为(0.5,0.5),实现了一个渐变的圆环进度。 希望我的回答能够帮到你!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值