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标签的基本使用情 ...
随机推荐
- reposync 同步yum仓库
reposync 同步远程yum仓库到本地 OPTIONS -h, --help 显示帮助 -c CONFIG, --config=CONFIG ...
- linux系统被入侵后处理经历【转】
背景 操作系统:Ubuntu12.04_x64 运行业务:公司业务系统,爬虫程序,数据队列. 服务器托管在外地机房. 突然,频繁收到一组服务器ping监控不可达邮件,赶紧登陆zabbix监控系统查看流 ...
- python 学习 有序字典
自定义创建有序字典类 dict的__getitem__方法 有些不同,想使用自定义__getitem__方法显示查询key的下标:需要研究 #/usr/bin/env python3 # -*- co ...
- 关于最新版本的log4net使用中遇到的问题
Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它提供了巨大的灵活性而不牺牲 ...
- 学习自动化工具gulp
<什么是gulp>官网地址:http://gulpjs.com/ gulp是可以自动化执行任务的工具,在开发流程里,一定有一些动作需要手工的重复的去执行,例如: ·把一个文件拷贝到另外一个 ...
- Linux镜像资源收集
1.企业 搜狐开源镜像站: http://mirrors.sohu.com/ 网易开源镜像站: http://mirrors.163.com/ 阿里开源镜像站: http://mirrors.aliy ...
- OAuth2.0 工作流程
重要术语 Authorization Server:授权服务器,能够成功验证资源拥有者和获取授权,并在此之后分发令牌的服务器: Resource Server:资源服务器,存储用户的数据资源,能够 ...
- Python语法点滴
string: string.capitalize() 把字符串的第一个字符大写 string.startswith(obj) string.endswith(obj) string.find(s ...
- JavaScript动态加载资源【js|css】示例代码
在开发过程中会用到各种第三方的插件,或者自己写在单独文件中的js方法库或者css样式,在html头部总是需要写一大堆的script和link标签,如果想要自己实现动态的引入资源文件,可以使用开源的re ...
- Windows下Discuz搭建论坛过程
搭建环境:Win7 + XAMPP5.5 + Discuz3.2 GBK 官方论坛下载安装包,解压,把upload文件夹拷贝到网站文档根目录(例如我的为:D:\IT\XAMPP5.5\htdocs\) ...