android自定义圆角实线边框,圆角虚线边框,直实线,虚实线,半圆角边框
2015-09-29 15:43
483 查看
先上图。
<img src="http://img.my.csdn.net/uploads/201510/05/1444048517_3752.png-thumb.jpg" width="1080" height="1920" style="font-family: Arial, Helvetica, sans-serif;" alt="" />
<span style="font-family: Arial, Helvetica, sans-serif;">在现实项目开发中,单纯的Button,EditText等控件远远不能满足我们项目的UI设计需求,这时候,我们就需要自己动手丰衣足食啦。接下来先给大家介绍一些属性,备注写的都非常清楚啦,我就不啰嗦啦。</span>
<?xml version="1.0" encoding="utf-8"?> <!--android:shape属性代表绘制的图形形状 retangle;矩形,oval:椭圆 ,line:线 ring,环形--> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="###"> <!--stroke主要给我们所要画的图形进行描边 color:边框颜色,width:边框宽度,dashGap:虚线框的间隔,dashWidth:虚线框的宽度--> <stroke android:width="###" android:color="###" android:dashGap="###" android:dashWidth="###" /> <!--corners主要是设置我们所画图形四个角的半径 radius:四角半径 bottomLeftRadius:左下角半径, bottomRightRadius:右下角半径,topLeftRadius:左上角半径,topRightRadius:右上角半径--> <corners android:bottomLeftRadius="###" android:bottomRightRadius="###" android:radius="###" android:topLeftRadius="###" android:topRightRadius="###" /> <!--padding主要设置内边距,也就是你装载的内容(大部分是Textview或者button)离图形边框的距离 bottom:下内边距,left:左内边距,right:右内边距,top:上内边距--> <padding android:bottom="###" android:left="###" android:right="###" android:top="###" /> <!--这个就不需要讲了吧--> <size android:width="###" android:height="###" /> <!--主要设置你所画图形的填充色--> <solid android:color="###"/> <!--gradient主要指定一个渐变颜色的形状。--> <gradient android:angle="###" android:centerColor="###" android:centerX="###" android:centerY="###" android:gradientRadius="###" android:endColor="###" android:startColor="###" android:type="###" android:useLevel="###"/> </shape>
接下来我们看最顶上的"哈哈"与"嘻嘻"。通过corners设置左下角和左上角的半径为5dp,右上角,右下角半径为0dp,我们就可以得到左边圆角,右边直角的边框啦。
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <stroke android:width="1.2dp" android:color="#6f4189" /> <solid android:color="#6f4189" /> <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="0dp" android:topLeftRadius="5dp" android:topRightRadius="0dp" /> <padding android:bottom="2dp" android:left="12dp" android:right="12dp" android:top="2dp" /> </shape> </item> </layer-list>下面一样,通过corners设置右下角和右上角的半径为5dp,左上角,左下角半径为0dp,我们即可得到左边直角,右边圆角的边框。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape> <stroke android:width="1.2dp" android:color="#6f4189" /> <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="5dp" android:topLeftRadius="0dp" android:topRightRadius="5dp" /> <solid android:color="#00000000" /> <padding android:bottom="2dp" android:left="12dp" android:right="12dp" android:top="2dp" /> </shape> </item> </layer-list>
它俩再加上viewpager就可以实现很多App上都有的左右滑动翻页效果啦。
我们再看图中的用户名和密码输入框,至于整个框框就不说啦,和上面的'嘻嘻','哈哈'一个原理,主要给大家介绍一下中间的红线。实现很简单,我们只需要设置android:shape="line",然后通过stoke的android:width设置直线的宽度,android;color设置直线的颜色即可。
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <stroke android:width="1.2dp" android:color="#ff4323"/> </shape>
让其在页面的显示代码如下
<LinearLayout android:id="@+id/straight_line" android:layout_width="fill_parent" android:layout_height="2dp" android:background="@drawable/line" android:orientation="vertical"></LinearLayout>
其实设置直线还有种跟直观的方法,通过<view/>来设置,在这里就不细讲,大家可以自行百度。
接下来我们看看下面的三个登录框框,重点给大家讲讲最后面那个"断点"虚线框框。
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="5dp"/> <solid android:color="#E67e22"/> </shape> <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="5dp"/> <stroke android:color="#E67e22" android:width="1.0dp"/> </shape>
其中color是定义虚线的颜色,dashGap定义的是虚线的间隔,width定义的是虚线的大小,dashWidth定义虚线的宽度。</span>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="5dp"/> <stroke android:color="#E67e2 83a3 2" android:width="1.0dp"/> </shape>
相关文章推荐
- Android 酷炫 倒计时的实现
- Android读取SD卡.TXT文本内容
- Android自定义效果 简易示波器 (1)
- Android 可拖拽 GridView 并且实时切换和拖动到下部删除
- apk安装时预留空间判断
- android之字体阴影效果
- Android关机充电时,充电的动画和背景方框有错位,要怎样调整?
- 避免Android内存泄露
- android DDMS 连接真机,用file explore看不到data/data文件夹的解决办法
- Android反编译
- android关于属性动画的七个使用案例
- android进阶必备案例(小案例)(持续更新)
- Android效果:SeekBar的简单使用
- Android第五十二期 - 云之讯的代码混淆
- Android之Handler用法总结
- android 应用分配内存查看代码
- (转载)android多线程详解之Handler
- Android Studio导入github下载的工程
- android项目实战 --ListView 头部ViewPager广告轮询图效果
- Android actionbar 使用简介