本文主要分享圆角边框与圆角背景的实现方式。该方式的实现,须要了解shape的使用。该部分的具体介绍,请阅读博客http://blog.csdn.net/mahoking/article/details/23672271。文中有较具体的介绍。

【转载使用,请注明出处:http://blog.csdn.net/mahoking

 例如以下是演示的shape_layout.xml模板。

  1. <?
  2.  
  3. xml version="1.0" encoding="utf-8"?>
  4. <shape xmlns:android="http://schemas.android.com/apk/res/android" >
  5. <!-- 填充色 -->
  6. <solid android:color="#CCFF99"/>
  7. <!-- 圆角 -->
  8. <corners android:radius="10dp"/>
  9. </shape>

为了显示的好看与协调,本案创建了多个shape_*.xml文件。各个shape_*.xml文件仅仅是solid填充色的配置不同,读者能够依据自己的设计与喜好自行搭配。

在本文的而最后,会展示对应Demo截图。

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android" >
  3. <!-- 填充色 -->
  4. <solid android:color="#FF9999"/>
  5. <!-- 圆角 -->
  6. <!-- android:radius 设置角的弧度,值越大角越圆-->
  7. <corners android:radius="10dp"/>
  8. </shape>

创建Activity(RoundCornerActivity),相应的布局文件为activity_01_round_corner.xml。

RoundCornerActivity

  1. /**
  2. *@describe 圆角边框、圆角背景的实现演示
  3. *@date 2014-8-24 22:35:49
  4. */
  5. public class RoundCornerActivity extends Activity{
  6.  
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_01_round_corner);
  11.  
  12. }
  13. }

activity_01_round_corner.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6.  
  7. <TextView
  8. android:layout_width="match_parent"
  9. android:layout_height="20dp"
  10. android:layout_marginLeft="15dp"
  11. android:layout_marginRight="15dp"
  12. android:layout_marginTop="5dp"
  13. android:background="@drawable/shape_01_round_corner_textview"
  14. android:gravity="center"
  15. android:text="圆角背景与边框演示" />
  16.  
  17. <LinearLayout
  18. android:layout_width="match_parent"
  19. android:layout_height="60dp"
  20. android:layout_marginLeft="15dp"
  21. android:layout_marginRight="15dp"
  22. android:layout_marginTop="10dp"
  23. android:background="@drawable/shape_01_round_corner_layout" >
  24. </LinearLayout>
  25.  
  26. <TextView
  27. android:layout_width="match_parent"
  28. android:layout_height="20dp"
  29. android:layout_marginLeft="15dp"
  30. android:layout_marginRight="15dp"
  31. android:layout_marginTop="5dp"
  32. android:background="@drawable/shape_01_round_corner_textview"
  33. android:gravity="center"
  34. android:text="下面是特效演示" />
  35.  
  36. <LinearLayout
  37. android:layout_width="match_parent"
  38. android:layout_height="wrap_content"
  39. android:layout_marginTop="10dp"
  40. android:orientation="horizontal" >
  41.  
  42. <LinearLayout
  43. android:layout_width="match_parent"
  44. android:layout_height="wrap_content"
  45. android:layout_marginLeft="5dp"
  46. android:layout_marginRight="5dp"
  47. android:layout_weight="1"
  48. android:orientation="vertical" >
  49.  
  50. <TextView
  51. android:layout_width="match_parent"
  52. android:layout_height="120dp"
  53. android:background="@drawable/shape_01_round_corner_textview_ma"
  54. android:gravity="center"
  55. android:text="马"
  56. android:textSize="60dp" />
  57. </LinearLayout>
  58.  
  59. <LinearLayout
  60. android:layout_width="match_parent"
  61. android:layout_height="wrap_content"
  62. android:layout_marginLeft="5dp"
  63. android:layout_marginRight="5dp"
  64. android:layout_weight="1"
  65. android:orientation="vertical" >
  66.  
  67. <TextView
  68. android:layout_width="match_parent"
  69. android:layout_height="55dp"
  70. android:background="@drawable/shape_01_round_corner_textview_yi"
  71. android:gravity="center"
  72. android:text="意"
  73. android:textSize="30dp" />
  74.  
  75. <TextView
  76. android:layout_width="match_parent"
  77. android:layout_height="55dp"
  78. android:layout_marginTop="10dp"
  79. android:background="@drawable/shape_01_round_corner_textview_ran"
  80. android:gravity="center"
  81. android:text="然"
  82. android:textSize="30dp" />
  83. </LinearLayout>
  84. </LinearLayout>
  85.  
  86. </LinearLayout>

切忌不要忘记在AndroidManifest.xml中注冊该Activity。

  1. <application
  2. android:allowBackup="true"
  3. android:icon="@drawable/uisharing_ico"
  4. android:label="@string/app_name"
  5. android:theme="@style/AppTheme" >
  6. <activity
  7. android:name="com.mahaochen.app.uisharing.example01.RoundCornerActivity"
  8. android:screenOrientation="portrait"
  9. android:label="@string/app_name">
  10. <intent-filter>
  11. <action android:name="android.intent.action.MAIN" />
  12. <category android:name="android.intent.category.LAUNCHER" />
  13. </intent-filter>
  14. </activity>
  15. </application>

执行该项目,效果例如以下:

 

【Android UI】案例02 圆角边框、圆角背景的实现(shape)的更多相关文章

  1. Android UI(一)Layout 背景局部Shape圆角设计

    Jeff Lee blog:   http://www.cnblogs.com/Alandre/  (泥沙砖瓦浆木匠),retain the url when reproduced ! Thanks ...

  2. CSS3(1)---圆角边框、边框阴影

    CSS3(1)---圆角边框.边框阴影 CSS3可以简单理解成是CSS的增强版,它的优点在于不仅有利于开发与维护,还能提高网站的性能. 一.圆角边框 圆角在实际开放过程中,还是蛮常见的.以前基本是通过 ...

  3. 第50天学习打卡(CSS 圆角边框 盒子阴影 定位)

    4.4圆角边框 圆角边框:  <!DOCTYPE html> <html lang="en"> <head>     <meta char ...

  4. css3如何实现圆角边框

    圆角边框是css3新增属性,在圆角边框出现之前,前端开发有的采用整块的圆角图片作为背景,有的采用小的圆角图片分别放在元素的四角,非常麻烦,灵活性差,也达到降低了网站的整体性能,而圆角边的出现则降低了开 ...

  5. CSS3 02. 边框、边框圆角、边框阴影、边框图片、渐变、线性渐变、径向渐变、背景、过渡transition、2D转换

    边框圆角 border-radius 每个角可以设置两个值,x值.y值 border-top-left-radius:水平半径 垂直半径 border-radius:水平半径/垂直半径 border- ...

  6. HackTwelve 为背景添加圆角边框

    1.概要:     ShapeDrawable是一个为UI控件添加特效的好工具.这个技巧适用于那些可以添加背景的控件 2.添加圆角边框其实就是添加的背景那里不是直接添加图片,而是添加一个XML文件即可 ...

  7. Android布局实现圆角边框

    首先,在res下面新建一个文件夹drawable,在drawable下面新建三个xml文件:shape_corner_down.xml.shape_corner_up.xml和shape_corner ...

  8. 50个Android开发技巧(12 为控件加入圆角边框)

    控件的圆角边框能够使你的App看起来更美观,事实上实现起来也非常easy. (原文地址:http://blog.csdn.net/vector_yi/article/details/24463025) ...

  9. Android布局中实现圆角边框

    设置corners_bg.xml 设置边框圆角可以在drawable-mdpi目录里定义一个xml: <?xml version="1.0" encoding="u ...

随机推荐

  1. 51 nod 1431 快乐排队

    1431 快乐排队 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  关注 有一群人在排队,如果某个人想排到前面去,可以花 ...

  2. Ruby print

    Ruby print

  3. MySQL5.7 的 错误堆栈缓冲

    什么是错误缓冲堆栈呢? 举个非常简单的样例,比方运行以下一条语句:mysql> INSERT INTO t_datetime VALUES(2,'4','5');ERROR 1292 (2200 ...

  4. 混合高斯模型的EM求解(Mixtures of Gaussians)及Python实现源代码

    今天为大家带来混合高斯模型的EM推导求解过程. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHVhbnl1YW5zZW4=/font/5a6L5L2T/ ...

  5. 多本Web前端深度修炼书籍(提供网盘下载链接)

    书籍介绍:这本书涵盖了html5新增标签和功能,而且提供了jquerymobile,Phonegap,Sencha Touch框架的介绍和应用,最后还带了一个移动web应用的样例,绝对是移动web开发 ...

  6. 《从零開始学Swift》学习笔记(Day 46)——下标重写

    原创文章.欢迎转载.转载请注明:关东升的博客 下标是一种特殊属性. 子类属性重写是重写属性的getter和setter訪问器,对下标的重写也是重写下标的getter和setter訪问器. 以下看一个演 ...

  7. 敏捷自己主动化单元測试 (从前台 JavaScript 至后台 Java)

    此份材料的内容适用于前台 JavaScript 与后台 Java 的单元測试◦ 希望, 能协助开发者可在最短的时间内, 开展单元測试的工作◦ 附件: 敏捷自己主动化单元測试 例子代码: QUnit 例 ...

  8. Win7上从硬盘安装Debian

    近期一直想将笔记本搞成Win7+Debian双系统.由于无论怎样优化,2G内存的Win7笔记本上开个Linux虚拟机都实在吃力. 经过一段时间的资料搜索.并阅读Debian官方的安装文档,今天最终实现 ...

  9. 上传文件 nginx 413错误

    nginx : 413 Request Entity Too Large 上传文件过程发生413 Request Entity Too Large错误,翻译为请求实体过大,断定为nginx限制了请求体 ...

  10. Eclipse 更新Android SDK后,新建项目出现appcompat_v7project的相关问题

    Eclipse 更新Android SDK后,新建项目出现各种问题.网上各种解决方式,搞了好久,总结一下. 1.出现error: Error retrieving parent for item: N ...