Android之最简单的ImageView加边框方法
2013-11-05 16:00
274 查看
转自:http://www.th7.cn/Program/Android/201301/120345.shtml
通常情况下,如果我们要给ImageView加上边框,比如宽为3dp的灰色框,是自己定义一个MyImageView类,继承自ImageView,在其onDraw方法中画canvas。
还有设置一个带有边框的背景图片的方法。
这里给出一种简单方法,既不需要创建衍生的类,也不需要准备图片。采用xml定义的方式实现。
背景定义xml: bg_border.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_border"
android:padding="3dp"
/>
通常情况下,如果我们要给ImageView加上边框,比如宽为3dp的灰色框,是自己定义一个MyImageView类,继承自ImageView,在其onDraw方法中画canvas。
还有设置一个带有边框的背景图片的方法。
这里给出一种简单方法,既不需要创建衍生的类,也不需要准备图片。采用xml定义的方式实现。
背景定义xml: bg_border.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_border"
android:padding="3dp"
/>
相关文章推荐
- Android最简单的Imageview加边框的方法
- Android之最简单的ImageView加边框方法
- Android之最简单的ImageView加边框方法
- Android之最简单的ImageView加边框方法
- Android之最简单的ImageView加边框方法
- 转载 Android简单实现ImageView的加边框颜色的方法
- android中ImageView设置图片边框的方法
- android ImageView点击时背景图修改(简单方法)
- Android编程简单实现ImageView点击时背景图修改的方法
- 简单实现ImageView的加边框颜色的方法
- 简单实现ImageView的加边框颜色的方法
- Android 简单实现圆形ImageView添加双层圆形边框
- android Imageview去除边框
- android ImageView实现圆角(xml实现方法)
- android控件-ImageView使用方法整理
- Android中使用GridView和ImageViewSwitcher实现电子相册简单功能
- Android 从imageview中获得bitmap的方法
- Android 从ImageView中获取Bitmap对象方法
- Android之ImageView的加边框颜色的几种实现方式
- Android SmartImageView框架的简单实用