均属于笔记,仅供个人参考,有问题欢迎指正,整理模式

Android中使用shape来定义控件的一些简单显示属性,如按钮的背景等,应用灵活方便。

1,示例代码:

<?xml version="1.0" encoding="utf-8"?> 

 

     

       

            android:shape="rectangle"> 

             

           

                android:startColor="#55B4FE"   

                android:endColor="#3d8FFB"   

                android:angle="-90" 

                android:type="linear"/>   

               

           

                android:color="#d3d3d3" 

                /> 

               

           

                android:topRightRadius="0dp"     

                android:bottomLeftRadius="10dp"   

                android:topLeftRadius="0dp"     

                android:bottomRightRadius="10dp"     

                /> 


                       

     

     

       

            android:shape="rectangle"> 


                       

               

           

                android:color="#d3d3d3" 

                /> 

               

           

                android:topRightRadius="0dp"     

                android:bottomLeftRadius="10dp"   

                android:topLeftRadius="0dp"     

                android:bottomRightRadius="10dp"     

                /> 


         

     

 

2,说明:

gradient:渐变

android:startColor 渐变开始的颜色

android:endColor 渐变结束的颜色

android:centerColor 中间点的颜色

ndroid:angle是渐变角度,必须为45的整数倍。

android:type  linear线性渐变;radial径向渐变

android:gradientRadius 径向渐变的半径

solid:填充

android:color 使用的填充颜色

stroke:描边

android:width 描边的宽度,

android:color 描边的颜色。

我们还可以把描边弄成虚线的形式,设置方式为:

android:dashWidth="5dp" 一个'-'的宽度

android:dashGap="3dp" 间隔的宽度

corners:圆角

android:radius为角的弧度,值越大角越圆。

分开设置:

android:topRightRadius="20dp"    右上角 

android:bottomLeftRadius="20dp"    右下角 

android:topLeftRadius="1dp"    左上角 

android:bottomRightRadius="0dp"    左下角 

padding:内间隔

3,将代码保存在res/drawable目录中,在使用时直接引入文件即可,如:

    android:id="@+id/testButton" 

    android:layout_width="wrap_content" 

    android:layout_height="wrap_content" 

    android:background="@drawable/test_button_bg"/> 

4,示例代码和注释

<?xml version="1.0" encoding="utf-8"?> 

 

 

  xmlns:android="http://schemas.android.com/apk/res/android" 

  android:shape="rectangle"> 


   

 

    android:radius="8dp" 

    android:topLeftRadius="5dp" 

    android:topRightRadius="15dp" 

    android:bottomLeftRadius="20dp" 

    android:bottomRightRadius="25dp"

    /> 


   

 

    android:startColor="#FFFF0000" 

    android:endColor="#80FF00FF" 

    android:angle="45" 

    /> 


   

 

    android:left="10dp" 

    android:top="10dp" 

    android:right="10dp" 

    android:bottom="10dp" 

    /> 


   

 

    android:width="600dp" 

    /> 


   

 

    android:color="#ffff9d77" 

    /> 


   

 

    android:width="2dp" 

    android:color="#dcdcdc"

    /> 

更多相关文章

  1. android位图颜色模式的问题
  2. 10.Android之测试代码实现步骤
  3. Android Studio 单刷《第一行代码》系列 02 —— 日志工具 LogCa
  4. Android源代码编译命令m/mm/mmm/make分析
  5. android 各种控件颜色值的设置(使用Drawable,Color)
  6. React Native 调用原生Android/iOS代码实现拨号功能
  7. Android 基础——第一行代码读书笔记(1)
  8. [原]Android应用程序进程启动过程的源代码分析

随机推荐

  1. JNDI不会离我们太远
  2. 如何用c#获取服务器端元素的innerhtml(内部
  3. jsPlumb开发入门教程(实现html5拖拽连线)
  4. 产生一系列的网址
  5. html页面中给img标签的src属性赋值为一张
  6. 仿wordpress管理后台设计的后台管理框架
  7. Web前端-html页面-做过的一个公司的主页
  8. 网页中时光轴的简单实现
  9. HTML常用符号 & 运用
  10. 关于结构化、半结构化、非结构化问题