先上图

在现实项目开发中,单纯的Button,EditText等控件远远不能满足我们项目的UI设计需求,这时候,我们就需要自己动手丰衣足食啦。接下来先给大家介绍一些属性,备注写的都非常清楚啦,我就不啰嗦啦。
 <?xml version="1.0" encoding="utf-8"?>
<!--android:shape属性代表绘制的图形形状 retangle;矩形,oval:椭圆 ,line:线 ring,环形-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="###"> <!--stroke主要给我们所要画的图形进行描边 color:边框颜色,width:边框宽度,dashGap:虚线框的间隔,dashWidth:虚线框的宽度-->
<stroke
android:width="###"
android:color="###"
android:dashGap="###"
android:dashWidth="###" /> <!--corners主要是设置我们所画图形四个角的半径 radius:四角半径 bottomLeftRadius:左下角半径,
bottomRightRadius:右下角半径,topLeftRadius:左上角半径,topRightRadius:右上角半径-->
<corners
android:bottomLeftRadius="###"
android:bottomRightRadius="###"
android:radius="###"
android:topLeftRadius="###"
android:topRightRadius="###" /> <!--padding主要设置内边距,也就是你装载的内容(大部分是Textview或者button)离图形边框的距离
bottom:下内边距,left:左内边距,right:右内边距,top:上内边距-->
<padding
android:bottom="###"
android:left="###"
android:right="###"
android:top="###" /> <!--这个就不需要讲了吧-->
<size
android:width="###"
android:height="###" />
<!--主要设置你所画图形的填充色-->
<solid
android:color="###"/>
<!--gradient主要指定一个渐变颜色的形状。-->
<gradient
android:angle="###"
android:centerColor="###"
android:centerX="###"
android:centerY="###"
android:gradientRadius="###"
android:endColor="###"
android:startColor="###"
android:type="###"
android:useLevel="###"/>
</shape>

接下来我们看最顶上的"哈哈"与"嘻嘻"。通过corners设置左下角和左上角的半径为5dp,右上角,右下角半径为0dp,我们就可以得到左边圆角,右边直角的边框啦。

 <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item>
<shape android:shape="rectangle">
<stroke
android:width="1.2dp"
android:color="#6f4189" /> <solid android:color="#6f4189" />
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="5dp"
android:topRightRadius="0dp" /> <padding
android:bottom="2dp"
android:left="12dp"
android:right="12dp"
android:top="2dp" />
</shape>
</item> </layer-list>

下面一样,通过corners设置右下角和右上角的半径为5dp,左上角,左下角半径为0dp,我们即可得到左边直角,右边圆角的边框。

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

     <item>
<shape>
<stroke
android:width="1.2dp"
android:color="#6f4189" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="0dp"
android:topRightRadius="5dp" />
<solid android:color="#00000000" />
<padding
android:bottom="2dp"
android:left="12dp"
android:right="12dp"
android:top="2dp" />
</shape>
</item> </layer-list>

它俩再加上viewpager就可以实现很多App上都有的左右滑动翻页效果啦。

我们再看图中的用户名和密码输入框,至于整个框框就不说啦,和上面的'嘻嘻','哈哈'一个原理,主要给大家介绍一下中间的红线。实现很简单,我们只需要设置android:shape="line",然后通过stoke的android:width设置直线的宽度,android;color设置直线的颜色即可。

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1.2dp"
android:color="#ff4323"/>
</shape>

让其在页面的显示代码如下

 <LinearLayout
android:id="@+id/straight_line"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="@drawable/line"
android:orientation="vertical"/>

其实设置直线还有种跟直观的方法,通过<view/>来设置,在这里就不细讲,大家可以自行百度。

接下来我们看看下面的三个登录框框,重点给大家讲讲最后面那个"断点"虚线框框。下面最后一个代码模块是"断点"虚线框框的代码,其中color是定义虚线的颜色,dashGap定义的是虚线的间隔,width定义的是虚线的大小,dashWidth定义虚线的宽度。

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="5dp"/>
<solid
android:color="#E67e22"/>
</shape>
 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="5dp"/>
<stroke
android:color="#E67e22"
android:width="1.0dp"/>
</shape>
 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp" />
<stroke
android:color="#E67e22"
android:dashGap="5dp"
android:width="2dp"
android:dashWidth="1.0dp" />
</shape>

android自定义圆角实线边框,圆角虚线边框,直实线,虚实线,半圆角边框的更多相关文章

  1. android自定义listview实现圆角

    在项目中我们会经常遇到这种圆角效果,因为直角的看起来确实不那么雅观,可能大家会想到用图片实现,试想上中下要分别做三张图片,这样既会是自己的项目增大也会增加内存使用量,所以使用shape来实现不失为一种 ...

  2. android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)

    shape使用.渐变色.分割线.边框.半透明.半透明阴影效果. 首先简单了解一下shape中常见的属性.(详细介绍参看  api文档 ) 转载请注明:Rflyee_大飞: http://blog.cs ...

  3. (转)[原] Android 自定义View 密码框 例子

    遵从准则 暴露您view中所有影响可见外观的属性或者行为. 通过XML添加和设置样式 通过元素的属性来控制其外观和行为,支持和重要事件交流的事件监听器 详细步骤见:Android 自定义View步骤 ...

  4. [原] Android 自定义View 密码框 例子

    遵从准则 暴露您view中所有影响可见外观的属性或者行为. 通过XML添加和设置样式 通过元素的属性来控制其外观和行为,支持和重要事件交流的事件监听器 详细步骤见:Android 自定义View步骤 ...

  5. android 自定义Button,抛弃写shape文件

      标签: android 控件  自定义 2017年05月27日 17:52:13 611人阅读 评论(0) 收藏 举报 分类: 自定义View(2) 作者同类文章 X 版权声明:本文为博主原创文章 ...

  6. Android 自定义View合集

    自定义控件学习 https://github.com/GcsSloop/AndroidNote/tree/master/CustomView 小良自定义控件合集 https://github.com/ ...

  7. Android 自定义 view(三)—— onDraw 方法理解

    前言: 上一篇已经介绍了用自己定义的属性怎么简单定义一个view<Android 自定义view(二) -- attr 使用>,那么接下来我们继续深究自定义view,下一步将要去简单理解自 ...

  8. Android 自定义shape圆形按钮

    Shape的属性: solid 描述:内部填充 属性:android:color 填充颜色 size 描述:大小 属性: android:width 宽 android:height 高 gradie ...

  9. 【Android - 自定义View】之自定义View浅析

    1.概述 Android自定义View / ViewGroup的步骤大致如下: 1) 自定义属性: 2) 选择和设置构造方法: 3) 重写onMeasure()方法: 4) 重写onDraw()方法: ...

  10. CSS不用背景图片实现优惠券样式反圆角,凹圆角,反向半圆角,并且背景渐变

    日常开发过程中,特别是商城相关应用开发过程中,时常会遇到花里胡哨的设计图,比如优惠券样式,上图: 实现思路如下:     1.先写一个外容器,实现背景色渐变: Html: 1 <div clas ...

随机推荐

  1. No archetypes currently available. The archetype list will refresh when the indexes finish updating

    配置方法: 1. 在卡住的而画面点击"config" 2. 点击"Add remote catalog", 然后设置华为云的maven仓库地址, 然后点击&qu ...

  2. 莫烦TensorFlow_06 plot可视化

    import tensorflow as tf import numpy as np import matplotlib.pyplot as plt def add_layer(inputs, in_ ...

  3. Windows解决端口占用问题

    Windows解决端口占用问题 步骤 1. win + R,输入cmd回车进入dos界面 2. 输入netstat -ano|findstr 8080 查看占用8080端口的进程 3. 输入taskk ...

  4. 【oracle】迁表结构和数据

    背景:把一些表和数据从某库迁到另一个库 1.命令框: exp yktsh/yktsh_2019@orcl30 file=d:\yktsh20191201.dmp log=d:\daochu; exp ...

  5. hadoop 输入路径用正则表达式被默认处理为多个参数的问题

    运行命令 hadoop jar   wordcount.jar   com.WordCount  /inpath/*{beijing,shanghai,guangzhou}*   /outpath/ ...

  6. nwjs-打包

    1: 将项目内所有文件压缩成一个压缩包 app.zip 2: 将压缩包重命名为 app.nw 3: 将压缩包放置到 下载解压后的 nw.js 根目录下 4: shift+鼠标右键 选择在此处打开命令窗 ...

  7. 关于c语言的逻辑短路规则

    原来的代码是 if (temp == 3 && (a % b != 0 || b == 0 )){ printf("go"); } dev-c 报错: progra ...

  8. WPF 目录树绑定 与 遍历

    定义树节点,(编译环境VS2017) public class GBTreeNode : INotifyPropertyChanged { private string _deviceId = str ...

  9. springboot kafka生产者

    pom文件: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http ...

  10. luogu p2705 小球

    题目部分 题目描述 有 R 个红色盒子和 B 个蓝色盒子,还有 R 个红色小球和 B 个蓝色小球.每个盒子只能装一个小球,每个小球都要放在一个盒子里. 如果把一个红色小球放在一个红色盒子里,那么得分是 ...