Android中利用shape定制控件边框
来源:互联网 发布:淘宝网咖啡机 编辑:程序博客网 时间:2024/06/05 05:47
在日常android的开发过程中,我们会遇到这样的一个需求。我只想给控件加左边框或者右边框,当然方法有很多种了。下面就不列举了,我就分享一个我认为比较好的实现方式吧。
首先要了解shape中gradient的原理,这里就不多说了,不明白的就自己去google。
分别定义左边框、底边框、右边框、上边框。
left-border
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- left border --> <gradient android:angle="0" android:startColor="#3666" android:centerColor="@android:color/transparent" android:centerX="1%" /></shape>
bottom-border
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- bottom border --> <gradient android:angle="90" android:startColor="#3F00" android:centerColor="@android:color/transparent" android:centerX="1%" /></shape>right-border
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- right border --> <gradient android:angle="180" android:startColor="#3666" android:centerColor="@android:color/transparent" android:centerX="1%" /></shape>top-border
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- top border --> <gradient android:angle="270" android:startColor="#3666" android:centerColor="@android:color/transparent" android:centerX="1%" /></shape>
好了,左边框、底边框、右边框、上边框已经定义好了,接下来就是排列组合问题了。
举例:
底边框+右边框
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/bottom_border"/> <item android:drawable="@drawable/right_border"/></layer-list>
以此类推,eclipse中的layout或者android studio的preview中可能看不到渲染效果,但是运行时效果的真实展现的。大家试试吧
转自 http://www.th7.cn/Program/Android/201503/401232.shtml
在日常android的开发过程中,我们会遇到这样的一个需求。我只想给控件加左边框或者右边框,当然方法有很多种了。下面就不列举了,我就分享一个我认为比较好的实现方式吧。
首先要了解shape中gradient的原理,这里就不多说了,不明白的就自己去google。
分别定义左边框、底边框、右边框、上边框。
left-border
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- left border -->
<gradient
android:angle="0"
android:startColor="#3666"
android:centerColor="@android:color/transparent"
android:centerX="1%"
/>
</shape>
bottom-border
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- bottom border -->
<gradient
android:angle="90"
android:startColor="#3F00"
android:centerColor="@android:color/transparent"
android:centerX="1%"
/>
</shape>
right-border
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- right border -->
<gradient
android:angle="180"
android:startColor="#3666"
android:centerColor="@android:color/transparent"
android:centerX="1%"
/>
</shape>
top-border
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- top border -->
<gradient
android:angle="270"
android:startColor="#3666"
android:centerColor="@android:color/transparent"
android:centerX="1%"
/>
</shape>
好了,左边框、底边框、右边框、上边框已经定义好了,接下来就是排列组合问题了。
举例:
底边框+右边框
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/bottom_border"/>
<item android:drawable="@drawable/right_border"/>
</layer-list>
以此类推,eclipse中的layout或者android studio的preview中可能看不到渲染效果,但是运行时效果的真实展现的。大家试试吧
转自 http://www.th7.cn/Program/Android/201503/401232.shtml
0 0
- Android中利用shape定制控件边框
- Android中利用shape定制控件边框
- Android中利用shape定制控件边框
- Android UI 利用Drawable Shape给控件加边框/立体效果
- android shape总结 和控件样式定制
- android shape总结 和控件样式定制
- android中通过shape定制图形效果
- android shape实现控件圆角,背景,边框等属性
- Android shape 矩形边框
- android shape 边框
- Android开发学习笔记:利用drawable中xml文件编写自定义控件样式(shape)
- Android shape属性在xml中自定义边框
- Android drawable shape绘制边框
- Android 使用shape添加边框
- Android通过shape实现边框
- android shape的使用 边框
- android shape绘制组件边框
- Android通过shape实现边框
- 浅谈java学习--针对JAVA初学者的建议
- 背包整理模板
- [前端] JS实现文件下载
- Fedora10虚拟机上网:桥接方式
- iOS 7使用boundingRectWithSize
- Android中利用shape定制控件边框
- ACM-两点距离
- Android自动化压力测试图解教程——Monkey工具
- jvm hotspot虚拟机研究
- webrtc (5) 在Webrtc中集成H264 Codec
- 如何使用adb查看各个文件属性详细信息
- Double值取得小数点后两位的若干方法
- exe4j生成的exe文件怎样才能在没有装JDK的电脑上运行
- svn设置忽视某个文件夹不提交 Eclipse VS2012