android在布局边缘位置处理圆角的两个办法:

1),一个是直接让美工切一张带有圆角的图片。

2),使用shape来解决。

第一种不在赘述,主要讲一下第二中方法来实现。

上边缘出现圆角,下边缘正常的shape处理:

文件位置:drawable/shape_top.xml

shape_top.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape>
<gradient android:angle="270" android:endColor="#f0f0f0" android:startColor="#f0f0f0" /> <stroke android:width="1dp" android:color="#dddddd" /> <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape></item>
<item android:state_focused="true"><shape>
<gradient android:angle="270" android:endColor="#f0f0f0" android:startColor="#f0f0f0" /> <stroke android:width="1dp" android:color="#dddddd" /> <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape></item>
<item><shape>
<gradient android:angle="270" android:endColor="#ffffff" android:startColor="#ffffff" /> <stroke android:width="1dp" android:color="#ffffff" /> <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape></item> </selector>

在布局文件中加上android:background="@drawable/shape_top"

没有圆角的shape设置:

文件位置:drawable/shape_middle.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape>
<gradient android:angle="270" android:endColor="#f0f0f0" android:startColor="#f0f0f0" /> <stroke android:width="1dp" android:color="#dddddd" /> <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape></item>
<item android:state_focused="true"><shape>
<gradient android:angle="270" android:endColor="#f0f0f0" android:startColor="#f0f0f0" /> <stroke android:width="1dp" android:color="#dddddd" /> <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape></item>
<item><shape>
<gradient android:angle="270" android:endColor="#ffffff" android:startColor="#ffffff" /> <stroke android:width="1dp" android:color="#ffffff" /> <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape></item> </selector>

在布局文件中加上android:background="@drawable/shape_middle"

下边缘出现圆角,上边缘不出现圆角的功能实现:

位置:drawable/shape_down.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape>
<gradient android:angle="270" android:endColor="#f0f0f0" android:startColor="#f0f0f0" /> <stroke android:width="1dp" android:color="#dddddd" /> <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape></item>
<item android:state_focused="true"><shape>
<gradient android:angle="270" android:endColor="#f0f0f0" android:startColor="#f0f0f0" /> <stroke android:width="1dp" android:color="#dddddd" /> <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape></item>
<item><shape>
<gradient android:angle="270" android:endColor="#ffffff" android:startColor="#ffffff" /> <stroke android:width="1dp" android:color="#ffffff" /> <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape></item> </selector>

在布局文件中加上android:background="@drawable/shape_down"

希望对各位有所帮助,如果有错误,请指正。谢谢

shape的使用的更多相关文章

  1. OpenCASCADE Shape Location

    OpenCASCADE Shape Location eryar@163.com Abstract. The TopLoc package of OpenCASCADE gives resources ...

  2. Drawable实战解析:Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)

    Android XML shape 标签使用详解   一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景. ...

  3. Android GradientDrawable(shape标签定义) 静态使用和动态使用(圆角,渐变实现)

    Android GradientDrawable使用优势: 1. 快速实现一些基本图形(线,矩形,圆,椭圆,圆环) 2. 快速实现一些圆角,渐变,阴影等效果 3. 代替图片设置为View的背景 4. ...

  4. AlloyRenderingEngine之Shape

    写在前面 不读文章,只对代码感兴趣可以直接跳转到这里 https://github.com/AlloyTeam/AlloyGameEngine 然后star一下,多谢支持:). 游戏或者应用中,不是所 ...

  5. 浅谈Android样式开发之shape

    引言 在Android开发中我们很多情况都是使用图片来展示相关效果,今天我就来详细介绍下Android下使用Shape来进行简单UI的开发.一方面这些是Android开发的基础,另一方面这方面的知识可 ...

  6. VSTO PowerPoint 代码删除Shape后再恢复出现无法再次获取的问题

    做PowerPoint的VSTO插件项目,遇到个很奇怪的问题,当代码执行删除某些Shape时,没问题,但是操作Undo也就是恢复后,无法再次获取到之前删除的对象,这种情况只在Office2007中出现 ...

  7. android shape的使用(转)

    shape用于设定形状,可以在selector,layout等里面使用,有6个子标签,各属性如下: <?xml version="1.0" encoding="ut ...

  8. 【Android进阶学习】shape和selector的结合使用(转)

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://liangruijun.blog.51cto.com/3061169/732310 ...

  9. [Android] Shape背景制作半圆或半边框

    实现原理使用layer-list对shape进行叠加显示. 直接上代码: <layer-list xmlns:android="http://schemas.android.com/a ...

  10. Android系列:res之shape制作

    大家好,pls call me francis. nice to me you. 本文将介绍使用在Android中使用shape标签绘制drawable资源图片. 下面的代码是shap标签的基本使用情 ...

随机推荐

  1. c#中命令copy已退出,返回值为1

    c#中命令copy已退出,返回值为1 本正经的道:董姐刚才你说的修心养性其中的'修心'我 有孕在身刚好由戴梦瑶顶替了她的位置按照的指示 ╋旆呆 湎术葶页 邾箕砜笳 烦璜卿廑 奶奶个腿儿的等下次非让你 ...

  2. jmeter里json path postprocessor的用法

    后置处理器添加 json path postprocessor. 用处: 当前接口响应返回的json中提取内容,作为变量可以在不同的请求中传递. 如下,从登陆接口返回的json中提取user id,变 ...

  3. linux 通过pid寻找程序路径的最简单命令

    在linux实际操作命令中,查看pid的方式有很多种,通过pid找程序路径的方式也有好几个,但是可能大家都忽略的一个很简单也是很实用的命令:pwdx. 比如要查找某个java编写的程序运行情况可通过j ...

  4. Linux下区分物理CPU、逻辑CPU和CPU核数

    ㈠ 概念           ① 物理CPU                             实际Server中插槽上的CPU个数              物理cpu数量,可以数不重复的 p ...

  5. Python编程工具IDLE快捷键

    IDLE编辑器快捷键 自动补全代码        Alt+/(查找编辑器内已经写过的代码来补全) 补全提示              Ctrl+Shift+space(默认与输入法冲突,修改之) (方 ...

  6. KVM下windows虚拟机使用virtio驱动

    KVM下windows虚拟机默认disk使用的是Qemu IDE硬盘,网卡默认是rtl8139网卡.为了使kvm主机在相同的配置下,有更好的效率,可以将网卡和磁盘替换成virtio的驱动. windo ...

  7. 分布式版本控制系统Git-----8.fst-forward与no fast foward

    当前分支合并到另一分支时,如果没有分歧解决,就会直接移动文件指针.这个过程叫做fastforward. 举例来说,开发一直在master分支进行,但忽然有一个新的想法,于是新建了一个develop的分 ...

  8. js实例--js滚动条缓慢滚动到顶部

    收集篇(已测)-- <html><head> <script type="text/javascript"> var currentPositi ...

  9. EasyuiAPI:基础

    一.EasyLoader(简单加载) locale属性:值类型是string locales属性:值类型是object 二.Draggable(拖动) 1.通过标签创建: <div id=&qu ...

  10. JS面向对象基础1

    根据之前看了面向对象相关的视频,按照自己的理解,整理出相关的笔记,以便自己的深入理解.     如果要判断两个数是否相等,将值乘以10或者100,转换成整数再进行比较 例如:a++与++a 短路运算符 ...