shape的使用
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的使用的更多相关文章
- OpenCASCADE Shape Location
OpenCASCADE Shape Location eryar@163.com Abstract. The TopLoc package of OpenCASCADE gives resources ...
- Drawable实战解析:Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)
Android XML shape 标签使用详解 一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景. ...
- Android GradientDrawable(shape标签定义) 静态使用和动态使用(圆角,渐变实现)
Android GradientDrawable使用优势: 1. 快速实现一些基本图形(线,矩形,圆,椭圆,圆环) 2. 快速实现一些圆角,渐变,阴影等效果 3. 代替图片设置为View的背景 4. ...
- AlloyRenderingEngine之Shape
写在前面 不读文章,只对代码感兴趣可以直接跳转到这里 https://github.com/AlloyTeam/AlloyGameEngine 然后star一下,多谢支持:). 游戏或者应用中,不是所 ...
- 浅谈Android样式开发之shape
引言 在Android开发中我们很多情况都是使用图片来展示相关效果,今天我就来详细介绍下Android下使用Shape来进行简单UI的开发.一方面这些是Android开发的基础,另一方面这方面的知识可 ...
- VSTO PowerPoint 代码删除Shape后再恢复出现无法再次获取的问题
做PowerPoint的VSTO插件项目,遇到个很奇怪的问题,当代码执行删除某些Shape时,没问题,但是操作Undo也就是恢复后,无法再次获取到之前删除的对象,这种情况只在Office2007中出现 ...
- android shape的使用(转)
shape用于设定形状,可以在selector,layout等里面使用,有6个子标签,各属性如下: <?xml version="1.0" encoding="ut ...
- 【Android进阶学习】shape和selector的结合使用(转)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://liangruijun.blog.51cto.com/3061169/732310 ...
- [Android] Shape背景制作半圆或半边框
实现原理使用layer-list对shape进行叠加显示. 直接上代码: <layer-list xmlns:android="http://schemas.android.com/a ...
- Android系列:res之shape制作
大家好,pls call me francis. nice to me you. 本文将介绍使用在Android中使用shape标签绘制drawable资源图片. 下面的代码是shap标签的基本使用情 ...
随机推荐
- nodejs问题整理--fs.exists无法正确判断文件的问题
fs.exists方法 方法说明: 测试某个路径下的文件是否存在.回调函数包含一个参数exists,true则文件存在,否则是false. 语法: fs.exists(path, callback) ...
- iOS开发工具箱
工欲善其事 必先利其器 最新重新安装了MacBook Air和Mac Pro的系统,彻底解决了一编译就报硬盘空间不足的问题.平时开发中比较常用的工具都需一一安装. XCode:没什么好说的,外星人都知 ...
- event 实现观察者模式
看了一些其他人写的,一下就晕了,还是自己写一个给自己看吧. 用event语法糖实现的观察者,与普通的实现,最大的区别在于,Subject的操作中不会直接触发Observer的Update,而是通过ev ...
- Struts2第二天
Struts2第二天 昨天: 1.Action的编写方式:实现Action接口.继承ActionSupport.自定义pojo作为action 2.action调用方法:默认的execute.meth ...
- Android非常有用的开源库介绍整理
Android开源库 自己一直很喜欢Android开发,就如博客副标题一样,我想做个好的App. 在摸索过程中,GitHub上搜集了很多很棒的Android第三方库,推荐给在苦苦寻找的开发者,而且我会 ...
- JS逻辑运算大于小于比较
遇到这个问题,结果测试了好半天终于发现原因, 例子: var az = $('#a').css('zIndex'); // 1001 var bz = $('#b').css('zIndex'); / ...
- VMWARE player 如何让 win2012 guest os 支持HYPER-V
在 vm player 下安装了 win2012 r2, 但是启用 hyper-v的时候,提示不支持, 这时候要修改 Open the file Location for this Virtual M ...
- iOS开发app上架流程之证书的制作
1.证书的制作:登陆 https: 1.1appid的注册 选择Identifiers 下的App IDs然后如图所示 点击加号,进入 App ID Description下的Name:这个是appI ...
- w3c School
w3c School : http://www.w3school.com.cn/h.asp
- Codeforces Round #366 (Div. 2)_B. Spider Man
B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...