Android兑现ImageView加边框
2014-01-03 15:00
417 查看
http://www.myexception.cn/image/1251426.html
-
Android实现ImageView加边框
对于一个Android ImageView,如果我们要加边框,比如宽为3dp的灰色框,我们怎么做呢?
一种方法,是自己定义一个MyImageView类,继承自ImageView,在其onDraw方法中画canvas。
还有一种比较取巧的方法是设置一个带有边框的背景图片。
这里给出一种简单方法,既不需要创建衍生的类,也不需要准备图片。采用xml定义的方式实现。
背景定义xml:bg_border1.xml
在Imageview定义页面上使用代码:
这样就可以使用了,效果如下图所示:
-
Android实现ImageView加边框
对于一个Android ImageView,如果我们要加边框,比如宽为3dp的灰色框,我们怎么做呢?
一种方法,是自己定义一个MyImageView类,继承自ImageView,在其onDraw方法中画canvas。
还有一种比较取巧的方法是设置一个带有边框的背景图片。
这里给出一种简单方法,既不需要创建衍生的类,也不需要准备图片。采用xml定义的方式实现。
背景定义xml:bg_border1.xml
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#EEEEEE" /> <stroke android:width="3dp" android:color="#EEEEEE" /> <corners android:radius="0dp" /> <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> </shape>
在Imageview定义页面上使用代码:
<ImageView android:id="@+id/iv_thumbnail" android:layout_height="63dp" android:layout_width="63dp" android:background="@drawable/bg_border1" android:padding="3dp" />
这样就可以使用了,效果如下图所示:
相关文章推荐
- Android ImageView 加边框
- Android ImageView加载圆形图片且同时绘制圆形图片的外部边缘边线及边框
- Android之ImageView的加边框颜色的几种实现方式
- android Imageview去除边框
- Android实现圆形Imageview,带白色边框
- Android ImageView 加边框
- Android ImageView加载圆形图片且同时绘制圆形图片的外部边缘边线及边框
- Android:通过自定义ImageView实现带边框的ImageView
- Android第三方框架universal-image-loader[图片缓存加载]及其OOM问题处理【常用】,CardView使用[给列表中项+边框]
- Android ImageView加载圆形图片且同时绘制圆形图片的外部边缘边线及边框
- Android实现ImageView加边框
- Android之最简单的ImageView加边框方法
- Android使用自定义ImageView为图片添加边框
- Android自定义ImageView给ImageView加边框
- android ImageView 加边框, 加阴影,shadow
- android ImageView 添加边框
- 转载 Android简单实现ImageView的加边框颜色的方法
- Android之最简单的ImageView加边框方法
- Android开发:ImageView 设置圆角边框
- android中ImageView设置图片边框的方法