android:shape

随缘101 随缘101     2022-07-31     265

关键词:

android:shape=["rectangle" | "oval" | "line" | "ring"]

shape的形状,默认为矩形,可以设置为矩形(rectangle)、椭圆形(oval)、线性形状(line)、环形(ring)

标签

corners ----------圆角
gradient ----------渐变
padding ----------内容离边界距离
size ------------大小 
solid  ----------填充颜色
stroke ----------描边 

注意的是corners的属性bottomLeftRadius为右下角、bottomRightRadius为左下角

------------------------------------------------

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

  android:innerRadius 尺寸,内环的半径。

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

  例如,如果android:innerRadiusRatio,表示内环半径等于环的宽度除以5,这个值是可以被覆盖的,默认为9.

  android:thickness 尺寸,环的厚度

  android:thicknessRatio 浮点型,以环的宽度比率来表示环的厚度,例如,如果android:thicknessRatio="2",

  那么环的厚度就等于环的宽度除以2。这个值是可以被android:thickness覆盖的,默认值是3.

  android:useLevel boolean值,如果当做是LevelListDrawable使用时值为true,否则为false.

-----------------------------------------------------------------------------------------

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    
    <!--
         圆角
         android:radius      整型 半径
      android:topLeftRadius      整型 左上角半径
      android:topRightRadius      整型 右上角半径
      android:bottomLeftRadius 整型 左下角半径
      android:bottomRightRadius 整型 右下角半径
     -->
     <corners  
        android:radius="8dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="15dp"
        android:bottomLeftRadius="20dp"
        android:bottomRightRadius="25dp"  
        />
     
     <!--
        渐变色
        android:startColor  颜色值 起始颜色
        android:endColor    颜色值 结束颜色
        android:centerColor 整型   渐变中间颜色,即开始颜色与结束颜色之间的颜色
        android:angle       整型   渐变角度(PS:当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。angle必须为45的整数倍)
        android:type        ["linear" | "radial" | "sweep"] 渐变类型(取值:linear、radial、sweep)
                            linear 线性渐变,这是默认设置
                            radial 放射性渐变,以开始色为中心。
                            sweep 扫描线式的渐变。
       android:useLevel   ["true" | "false"] 如果要使用LevelListDrawable对象,就要设置为true。设置为true无渐变。false有渐变色
       android:gradientRadius 整型 渐变色半径.当 android:type="radial" 时才使用。单独使用 android:type="radial"会报错。
       android:centerX        整型   渐变中心X点坐标的相对位置
       android:centerY   整型   渐变中心Y点坐标的相对位置
    -->
    <gradient
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="45"
        /> 
        
    <!--
          内边距,即内容与边的距离 
          android:left      整型 左内边距
          android:top   整型 上内边距
          android:right      整型 右内边距
          android:bottom 整型 下内边距
      -->
     <padding 
         android:left="10dp"
         android:top="10dp"
         android:right="10dp"
         android:bottom="10dp"
         />
     
    <!-- 
       size 大小
       android:width 整型 宽度
       android:height 整型 高度
    -->
    <size
        android:width="600dp"
        />
    
    <!--
        内部填充
        android:color 颜色值 填充颜色
    -->
    <solid 
        android:color="#ffff9d77"
        />
    
     <!--
         描边
         android:width 整型 描边的宽度
         android:color 颜色值 描边的颜色
         android:dashWidth 整型 表示描边的样式是虚线的宽度, 值为0时,表示为实线。值大于0则为虚线。
         android:dashGap      整型 表示描边为虚线时,虚线之间的间隔 即“ - - - --->
     <stroke 
        android:width="2dp"
        android:color="#dcdcdc"  
        /> 
</shape>

 

xml#android#shape#sample(代码片段)

查看详情

为 Shape 的笔画宽度设置动画

...题描述】:我有一个带有透明中心的粗圆圈:<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><solidandroid:color="@andro 查看详情

androiddrawable-shape(代码片段)

...mlversion="1.0"encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape=["rectangle"|"oval"|"line"|"ring"]><cornersandroid:radius="integer"android:topLeftRadius=... 查看详情

android里用shape画圆,怎么填充颜色

背景色那里改一下就行了<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"android:useLevel="false"><!--背景色--><solidandroid:color="@color/redbg"/><!--边框色--><strokeandroid:width=&q... 查看详情

android怎么利用shape实现圆形用户头像

...t;?xmlversion="1.0"encoding="UTF-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"android:useLevel="false"><solidandroid:color="@color/common_red"/><paddingandroid:left="2dp"... 查看详情

如何使用shape来画半圆和画虚线

...不出效果,需要跑真机才能看出效果。画虚线<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="line">//这句话一定不要漏了 查看详情

android shape xml以编程方式旋转可绘制更改颜色

】androidshapexml以编程方式旋转可绘制更改颜色【英文标题】:androidshapexmlrotateddrawablechangecolorprogrammatically【发布时间】:2014-03-2622:17:47【问题描述】:这是一个三角形的xml:<layer-listxmlns:android="http://schemas.android.com/apk/res/android"... 查看详情

Android Shape Drawable 改变属性

】AndroidShapeDrawable改变属性【英文标题】:AndroidShapeDrawablechangingattributes【发布时间】:2015-03-1316:55:37【问题描述】:我有几个形状可绘制资源,我想用作按钮的背景,它们是相似的,除了渐变开始和结束颜色以及笔触颜色。问... 查看详情

Android shape drawable xml未在设备或模拟器上绘制

】Androidshapedrawablexml未在设备或模拟器上绘制【英文标题】:Androidshapedrawablexmlnotdrawnondevicenoremulator【发布时间】:2011-11-3018:09:42【问题描述】:我就是想不通。我在res/drawable/start_light.xml中有这个形状<?xmlversion="1.0"encoding="utf-8"... 查看详情

android轮播图下面左右滑动的小圆点样式布局(代码片段)

...mlversion="1.0"encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"android:useLevel="false"><solidandroid:color="#fb435b"/><sizeandroid:width="5dp"a... 查看详情

在vb中人如何用shape控件画圆?

...t;?xmlversion="1.0"encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"android:useLevel="false"><solidandroid:color="@color/red"/><strokeandroid:width="1dp"androi... 查看详情

android学习(代码片段)

SHAPE:圆角和颜色渐变过度<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><!--圆角的半径--><cornersandroid:radius="20dp"/&g 查看详情

android实现隐私政策提示弹窗(代码片段)

...张圆角的图片,然后给button作为背景图片--><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><!--设置背景色--><solidandroid:color="#F59E27"/><!--设置圆角--><cornersandroid:r... 查看详情

android上阴影效果怎么做

...ne。可以在xml中通过定义一个背景来设置outline:<TextViewandroid:id="@+id/myview"...android:elevation="2dp"android:background="@drawable/myrect"/><!--res/drawable/myrect.xml--><shapexmlns:android="http://schemas.android.com/apk/res/and... 查看详情

你都知道么?android中21种drawable标签大全(代码片段)

...资源,其中用的最多的应该就是selector和shape。目前在Android中有21种drawable标签,了解和利用这些标签对我们的开发有很大的帮助。这个文章我们对这21种标签做一个介绍,让大家有一个印象。本文中有些资料取自网上&... 查看详情

android学习笔记33——资源shapedrawable

...XML文件的根元素是<shape.../>,该元素可指定如下属性:android:shape=["rectangle"|"oval"|"ling"|"ring"]——指定定义那种类型的几何图形。实例如下:椭圆、渐变 查看详情

android开发控件外边框自定义(代码片段)

1、在drawable里面新建自定义的资源文件shape<?xmlversion="1.0"encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle&quo 查看详情

安卓开发自定义按钮形状(代码片段)

...mlversion="1.0"encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><solidandroid:color="#43CD80"/><cornersandroid:radius="5dp"/></shape>实际效... 查看详情