android常用shape(直接copy)

新建shape文件,颜色需要自己定义

新建shape

shape属性:(默认矩形)

  • line--线
  • oval--椭圆
  • rectangle--圆角矩形

shape有6个属性节点

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

下面是常见常用shape直接copy代码,颜色根据自己需求设置整个文件当作background属性引用即可

一、

渐变色:


image.png

shape.xml

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

    <gradient
        android:startColor="@color/point_green"
        android:endColor="@color/actionsheet_blue"/>
    <size
        android:width="200dp"
        android:height="100dp"/>
</shape>

二、

圆角矩形框:


image.png

shape.xml

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
        <corners
          android:radius="15dp"/>
        <stroke
          android:width="2dp"
          android:color="@color/point_green"/>
        <size
          android:width="200dp"
          android:height="100dp"/>
</shape>

三、

圆角矩形实心:


image.png

shape.xml

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

  <corners
    android:radius="15dp"/>
  <solid
      android:color="@color/point_green"/>
  <size
    android:width="200dp"
    android:height="100dp"/>
</shape>

四、

圆角带边框实心:


image.png

shape.xml

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

  <corners
      android:radius="15dp"/>
  <stroke
    android:width="2dp"
    android:color="@color/color_green"/>
  <solid
    android:color="@color/login_button_bg_gray"/>
  <size
    android:width="200dp"
    android:height="100dp"/>
</shape>

五、

左圆角右直角:


image.png

shape.xml

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

  <corners
    android:topLeftRadius="15dp"
    android:bottomLeftRadius="15dp"/>
  <stroke
    android:width="2dp"
    android:color="@color/color_green"/>
  <solid
    android:color="@color/login_button_bg_gray"/>
  <size
    android:width="200dp"
    android:height="100dp"/>
</shape>

六、

圆框:


image.png

shape.xml

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

  <stroke
    android:width="2dp"
    android:color="@color/color_green"/>
  <solid
    android:color="@color/login_button_bg_gray"/>
  <size
    android:width="100dp"
    android:height="100dp"/>
</shape>

七、

虚线:


image.png

shape.xml

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="line">
  <stroke
    android:width="1dp"
    android:dashWidth="3dp"
    android:dashGap="8dp"
    android:color="@color/point_green"/>
</shape>

八、

虚线框:


image.png

shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
  <stroke
    android:width="1dp"
    android:dashWidth="3dp"
    android:dashGap="8dp"
    android:color="@color/point_green"/>
  <size
    android:width="200dp"
    android:height="100dp"/>
</shape>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,521评论 25 709
  • 记得刚开始学Android时,看着自己完全用系统控件写出的不忍直视的界面,对于如何做出不一样的按钮,让它们在不同状...
    biloba阅读 5,707评论 1 11
  • 概述 今天我们来探究一下android的样式。其实,几乎所有的控件都可以使用 background属性去引用自定义...
    CokeNello阅读 10,363评论 1 19
  • 去年夏天在自己老家园地拍的 设备:苹果6 加了一个镜头
    时光记忆师阅读 2,880评论 3 4
  • 书名:《西去的使节》 作者:梁越出版社:外文出版社版次:2007年11月第1版第3次印刷【精彩片段集锦 】 1...
    江语阅读 5,701评论 0 1