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. ntp升级

    1. 系统与软件版本 1.1 系统版本 CentOS6.5 x86_64 1.2 ntpd软件版本 ntp-4.2.8p9.tar.gz 1.3 下载地址 官方下载地址:http://support. ...

  2. C#多线程:深入了解线程同步lock,Monitor,Mutex,同步事件和等待句柄(中)

    本篇继续介绍WaitHandler类及其子类 Mutex,ManualResetEvent,AutoResetEvent的用法..NET中线程同步的方式多的让人看了眼花缭乱,究竟该怎么去理解呢?其实, ...

  3. python的模块!

    以下是对模块的理解,和总结 <1>模块是什么 模块是这样用的 import os 这就是导入了os模块 这和c语言里的#include<stdio.h>导入方式是一样的 导入了 ...

  4. delphi 关键字

    下面的关键字不能被重新定义或用作标志符:and array as asm begin case class const constructor destructor dispinterface div ...

  5. Java 服务器端手机验证码sdk

    感谢巨人们,站在巨人的肩膀上. 参考: http://blog.sina.com.cn/s/blog_80a6423d0102wm74.html#commonComment 1 点击生成验证码,发送到 ...

  6. 版本控制器:SVN

    版本控制器:SVN 开发中的实际问题 小明负责的模块就要完成了,就在即将Release之前的一瞬间,电脑突然蓝屏,硬盘光荣牺牲!几个月来的努力付之东流--需求之一:备份! 这个项目中需要一个很复杂的功 ...

  7. Spring第二天

    Spring第二天 整体课程安排(3天+2天): 第一天:Spring框架入门.IoC控制反转的配置管理.Spring Web集成.Spring Junit集成. 第二天:Spring AOP面向切面 ...

  8. CodeForces 702E Analysis of Pathes in Functional Graph

    倍增预处理. 先看一下这张图的结构,因为出度都是$1$,所以路径是唯一的,又因为每个点都有出度,所以必然有环,也就是一直可以走下去. 接下来我们需要记录一些值便于询问: 设$t[i][j]$表示从$i ...

  9. ZOJ 1926 Guessing Game

    #include<cstdio> ],s2[]; ]; ]; int bz; int main() { int n,i; while(~scanf("%d",& ...

  10. VB VBA VBS有什么区别?

    VB和VBA本就是同宗的姐妹,只不过姐姐VB的功夫要比妹妹VBA历害些.不过姐姐只会单打独斗是女强人:妹妹却只会傍大款(例如Office).姐姐有生育能力,是真正的女人:妹妹却不会生崽(生成.EXE) ...