在日常android的开发过程中,我们会遇到这样的一个需求。我只想给控件加左边框或者右边框,当然方法有很多种了。下面就不列举了,我就分享一个我认为比较好的实现方式吧。


首先要了解shape中gradient的原理,这里就不多说了,不明白的就自己去google。

分别定义左边框、底边框、右边框、上边框。

left-border

<?xml version="1.0" encoding="utf-8"?>
       android:shape="rectangle">
 
        android:angle="0"
      android:startColor="#3666"
      android:centerColor="@android:color/transparent"
      android:centerX="1%"
      />


bottom-border

<?xml version="1.0" encoding="utf-8"?>
       android:shape="rectangle">
 
        android:angle="90"
      android:startColor="#3F00"
      android:centerColor="@android:color/transparent"
      android:centerX="1%"
      />

right-border

<?xml version="1.0" encoding="utf-8"?>
       android:shape="rectangle">
 
        android:angle="180"
      android:startColor="#3666"
      android:centerColor="@android:color/transparent"
      android:centerX="1%"
      />

top-border

<?xml version="1.0" encoding="utf-8"?>
       android:shape="rectangle">
 
        android:angle="270"
      android:startColor="#3666"
      android:centerColor="@android:color/transparent"
      android:centerX="1%"
      />


好了,左边框、底边框、右边框、上边框已经定义好了,接下来就是排列组合问题了。

举例:

底边框+右边框

<?xml version="1.0" encoding="utf-8"?>

        android:drawable="@drawable/bottom_border"/>
 


以此类推,eclipse中的layout或者android studio的preview中可能看不到渲染效果,但是运行时效果的真实展现的。大家试试吧




更多相关文章

  1. Android基础教程(九)之自定义下拉菜单模式----Spinner与setDropD
  2. 朝花夕拾-android 自定义toast
  3. Android(安卓)音乐播放器的实现(一)自定义按钮的实现
  4. Android(安卓)- Handler 、AsyncTask(二)
  5. Android(安卓)自定义Gallery浏览图片
  6. Android(安卓)自定义progressDialog实现
  7. 谜之RxJava (一) —— 最基本的观察者模式
  8. 某android平板项目开发笔记--自定义sharepreference UI
  9. [Unity3D]Unity3D游戏开发之Unity与Android交互调用研究

随机推荐

  1. android activity 实现半透明Translucent
  2. android点击事件的分发过程
  3. Android(安卓)实现 WheelView
  4. Android(安卓)WIndow,WindowManager简单
  5. Android控制水平方向字体缩放android:tex
  6. android:shape的使用
  7. Android(安卓)Property Animation属性动
  8. android的一些常用属性的说明
  9. Android中使用jiecaovideoplayer播放视频
  10. Android(安卓)Studio中隐藏状态栏和标题