?
1
2
3
4
5
6
7
8
9
//设置颜色
    publicvoid setColour(intcolor){
        co = color;
    }
    //设置边框宽度
    publicvoid setBorderWidth(intwidth){
         
        borderwidth = width;
    }

具体实现:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
packagexiaosi.imageborder;
importandroid.app.Activity;
importandroid.graphics.Color;
importandroid.os.Bundle;
publicclass ImageBorderActivity extendsActivity {
    /** Called when the activity is first created. */
    privatemyImageView image = null;
    privatemyImageView image1 = null;
    @Override
    publicvoid onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
         
        image = (myImageView)findViewById(R.id.iamge);
        image.setColour(Color.YELLOW);
        image.setBorderWidth(10);
        image1 = (myImageView)findViewById(R.id.iamge1);
        image1.setColour(Color.GREEN);
        image1.setBorderWidth(5);
    }
}

main.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/playerbackground"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
     <xiaosi.imageborder.myImageView
         android:id="@+id/iamge"
         android:layout_width="200px"
         android:layout_height="230px"
         android:layout_alignParentRight="true"
         android:src="@drawable/v"
         android:layout_centerInParent="true"
         android:layout_marginRight="3px"
        />
     <xiaosi.imageborder.myImageView
         android:id="@+id/iamge1"
         android:layout_width="200px"
         android:layout_height="230px"
         android:layout_alignParentRight="true"
         android:src="@drawable/v"
         android:layout_centerInParent="true"
         android:layout_marginRight="3px"
        />
</LinearLayout>

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
packagexiaosi.imageborder;
importandroid.content.Context;
importandroid.graphics.Canvas;
importandroid.graphics.Paint;
importandroid.graphics.Rect;
importandroid.util.AttributeSet;
importandroid.widget.ImageView;
publicclass myImageView extendsImageView {
    privateint co;
    privateint borderwidth;
    publicmyImageView(Context context) {
        super(context);
    }
    publicmyImageView(Context context, AttributeSet attrs,
            intdefStyle) {
        super(context, attrs, defStyle);
    }
    publicmyImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    //设置颜色
    publicvoid setColour(intcolor){
        co = color;
    }
    //设置边框宽度
    publicvoid setBorderWidth(intwidth){
         
        borderwidth = width;
    }
    @Override
    protectedvoid onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // 画边框
        Rect rec = canvas.getClipBounds();
        rec.bottom--;
        rec.right--;
        Paint paint = newPaint();
        //设置边框颜色
        paint.setColor(co);
        paint.setStyle(Paint.Style.STROKE);
        //设置边框宽度
        paint.setStrokeWidth(borderwidth);
        canvas.drawRect(rec, paint);
    }
}

Android:给图片加边框相关推荐

  1. android给图片加边框,android 图片加边框 ImageView border 成效

    android 图片加边框 ImageView border 效果 1.布局文件 res/layout/some_page.xml android:id="@+id/respImageBor ...

  2. android给图片加边框,Android学习笔记进阶19之给图片加边框

    //设置颜色 public void setColour(int color){ co = color; } //设置边框宽度 public void setBorderWidth(int width ...

  3. android 加载进度,Android实现图片加载进度提示

    本文实例为大家分享了Android实现图片加载进度提示的具体代码,供大家参考,具体内容如下 先上图: 实现原理: 第一个控件的实现原理是重写ImageView的onDraw()方法,利用Canvas的 ...

  4. Android Glide图片加载框架(四)回调与监听

    文章目录 Android Glide图片加载框架系列文章 Android Glide图片加载框架(一)基本用法 Android Glide图片加载框架(二)源码解析之with() Android Gl ...

  5. Android Glide图片加载框架(三)缓存机制

    文章目录 一.缓存简介 二.缓存用法 内存缓存方式 磁盘缓存方式 三.缓存KEY 四.内存缓存 内存缓存流程 五.磁盘缓存 磁盘缓存流程 Android Glide图片加载框架系列文章 Android ...

  6. Android Glide图片加载框架(二)源码解析之into()

    文章目录 一.前言 二.源码解析 1.into(ImageView) 2.GlideContext.buildImageViewTarget() 3.RequestBuilder.into(Targe ...

  7. Android Glide图片加载框架(二)源码解析之load()

    文章目录 一.前言 二.源码分析 1.load() Android Glide图片加载框架系列文章 Android Glide图片加载框架(一)基本用法 Android Glide图片加载框架(二)源 ...

  8. Android Glide图片加载框架(二)源码解析之with()

    文章目录 一.前言 二.如何阅读源码 三.源码解析 1.with() Android Glide图片加载框架系列文章 Android Glide图片加载框架(一)基本用法 Android Glide图 ...

  9. Android Glide图片加载框架(一)基本用法

    文章目录 一.前言 二.简介 三.基本用法 第一步:调用 Glide.with() 方法创建加载图片的实例 第二步:调用 load() 方法指定待加载的图片资源 第三步:调用 into() 方法绑定显 ...

  10. 如何给照片加边框?图片加边框的3个实用方法

    分享3个良心好用的照片加相框工具,个个都是操作简单,还提供了丰富好看的边框模板,瞬间让照片变得有质感,大家可以根据自己的需求选择对应的工具进行添加. 1.改图鸭 一个免费的图片处理网站,提供几十种图片 ...

最新文章

  1. 未能加载文件或程序集“AspNetPager”或它的某一个依赖项。拒绝访问。(异常来自 HRESULT:0x80070005 (E_ACCESSDENIED))...
  2. token、cookie是什么
  3. idea设置文件多行显示
  4. python线程检测网段脚本!
  5. linux fedora yum安装docker-ce
  6. boost::mpl模块实现pair_view相关的测试程序
  7. 第17课:RDD案例(join、cogroup等实战)
  8. 关于Linux的close函数的注意点
  9. 3 天开发物联网应用!腾讯云 IoT 超级小程序来了
  10. python输入圆的半径公式_【同步练习】六年级数学上册圆的面积教材同步
  11. 【C/C++】BOOST 线程完全攻略 - 基础篇
  12. 验证码的旋转与放缩代码
  13. 阿里云oss文件分片、断点续传上传
  14. Solidity语言详解——view和pure函数的使用区别
  15. MySQL数据库笔记
  16. [程序员学英语]26个英文字母
  17. 使用绝热演化/量子退火算法求解矩阵本征态
  18. Python基础(三)Python容器:列表、元组、字典和集合
  19. 计算机基础(三)软件
  20. 《论语》原文及其全文翻译 学而篇9

热门文章

  1. 最近邻搜索算法flann Marius Muja and David G. Lowe
  2. idea无法下载源码 Sources not found for: org.springframework:spring-context:5.1.5.RELEAS
  3. 商务统计_5 用图表演示数据 - 茎叶图
  4. 第二期:关于大数据相关的问答汇总,关注持续更新中哦~
  5. php 使用xunsearch--迅搜
  6. PhD Debate-11 预告 | 矛与盾的对决——神经网络后门攻防
  7. python中pos函数,python pos是什么
  8. 移动Web开发字体格式选择(附.woff\.woff2 兼容性)
  9. 使用GLAD加载OpenGL的库
  10. 关于华三路由器nat映射ftp端口号登录服务器失败问题