Android中给图片加边框
需要重写ImageView
1
|
//设置颜色
|
2
|
public void setColour( int color){
|
3
|
co = color;
|
4
|
}
|
5
|
//设置边框宽度
|
6
|
public void setBorderWidth( int width){
|
7
|
|
8
|
borderwidth = width;
|
9
|
}
|
具体实现:
01
|
package xiaosi.imageborder;
|
02
|
|
03
|
import android.app.Activity;
|
04
|
import android.graphics.Color;
|
05
|
import android.os.Bundle;
|
06
|
|
07
|
public class ImageBorderActivity extends Activity {
|
08
|
/** Called when the activity is first created. */
|
09
|
private myImageView image = null ;
|
10
|
private myImageView image1 = null ;
|
11
|
@Override
|
12
|
public void onCreate(Bundle savedInstanceState) {
|
13
|
super .onCreate(savedInstanceState);
|
14
|
setContentView(R.layout.main);
|
15
|
|
16
|
image = (myImageView)findViewById(R.id.iamge);
|
17
|
image.setColour(Color.YELLOW);
|
18
|
image.setBorderWidth( 10 );
|
19
|
image1 = (myImageView)findViewById(R.id.iamge1);
|
20
|
image1.setColour(Color.GREEN);
|
21
|
image1.setBorderWidth( 5 );
|
22
|
}
|
23
|
}
|
main.xml
01
|
< LinearLayout
|
02
|
xmlns:android = "http://schemas.android.com/apk/res/android"
|
03
|
android:background = "@drawable/playerbackground"
|
04
|
android:layout_width = "fill_parent"
|
05
|
android:layout_height = "fill_parent" >
|
06
|
< xiaosi.imageborder.myImageView
|
07
|
android:id = "@+id/iamge"
|
08
|
android:layout_width = "200px"
|
09
|
android:layout_height = "230px"
|
10
|
android:layout_alignParentRight = "true"
|
11
|
android:src = "@drawable/v"
|
12
|
android:layout_centerInParent = "true"
|
13
|
android:layout_marginRight = "3px"
|
14
|
/>
|
15
|
< xiaosi.imageborder.myImageView
|
16
|
android:id = "@+id/iamge1"
|
17
|
android:layout_width = "200px"
|
18
|
android:layout_height = "230px"
|
19
|
android:layout_alignParentRight = "true"
|
20
|
android:src = "@drawable/v"
|
21
|
android:layout_centerInParent = "true"
|
22
|
android:layout_marginRight = "3px"
|
23
|
/>
|
24
|
</ LinearLayout >
|
01
|
package xiaosi.imageborder;
|
02
|
|
03
|
import android.content.Context;
|
04
|
import android.graphics.Canvas;
|
05
|
import android.graphics.Paint;
|
06
|
import android.graphics.Rect;
|
07
|
import android.util.AttributeSet;
|
08
|
import android.widget.ImageView;
|
09
|
|
10
|
public class myImageView extends ImageView {
|
11
|
|
12
|
private int co;
|
13
|
private int borderwidth;
|
14
|
public myImageView(Context context) {
|
15
|
super (context);
|
16
|
}
|
17
|
public myImageView(Context context, AttributeSet attrs,
|
18
|
int defStyle) {
|
19
|
super (context, attrs, defStyle);
|
20
|
}
|
21
|
|
22
|
public myImageView(Context context, AttributeSet attrs) {
|
23
|
super (context, attrs);
|
24
|
}
|
25
|
//设置颜色
|
26
|
public void setColour( int color){
|
27
|
co = color;
|
28
|
}
|
29
|
//设置边框宽度
|
30
|
public void setBorderWidth( int width){
|
31
|
|
32
|
borderwidth = width;
|
33
|
}
|
34
|
@Override
|
35
|
protected void onDraw(Canvas canvas) {
|
36
|
super .onDraw(canvas);
|
37
|
// 画边框
|
38
|
Rect rec = canvas.getClipBounds();
|
39
|
rec.bottom--;
|
40
|
rec.right--;
|
41
|
Paint paint = new Paint();
|
42
|
//设置边框颜色
|
43
|
paint.setColor(co);
|
44
|
paint.setStyle(Paint.Style.STROKE);
|
45
|
//设置边框宽度
|
46
|
paint.setStrokeWidth(borderwidth);
|
47
|
canvas.drawRect(rec, paint);
|
48
|
}
|
49
|
}
|
Android中给图片加边框相关推荐
- Android中的图片加载
Android中的图片加载所出现的问题 在Android的开发中,经常需要去加载图片,但是图片的尺寸有时候往往会很大,而我们的内存是有限的,加载进来的时候很有可能会造成内存溢出,这种结果也是我们不想看 ...
- 在网页中为图片加边框
图片加框其实很简单,在发表文章页面钩选"显示源代码",挑选一个下列喜欢的代码插入<DIV>中,再取消"显示源代码",画框就有了."图片地址 ...
- Android中给LineayLayout加边框
给Android的LinearLayout加边框分为两种方式,给LinearLayout整体加边框和给某一个边加边框 第一种:给整体加边框 在drawable文件夹中新建shape资源文件,将下列代码 ...
- html中给图片加边框带,CSS如何给图片加边框效果?
直接粘贴到BODY里面去事实 style="BORDER-RIGHT: #eeeeee 3px solid; BORDER-TOP: #eeeeee 3px solid; BORDER-LE ...
- android给图片加边框,android 图片加边框 ImageView border 成效
android 图片加边框 ImageView border 效果 1.布局文件 res/layout/some_page.xml android:id="@+id/respImageBor ...
- Android高效异步图片加载框架
概述 Android高效异步图片加载框架:一个高效的异步加载显示的图片加载框架,同时具备图片压缩,缓存机制等特性. 详细 代码下载:http://www.demodashi.com/demo/1214 ...
- 如何给照片加边框?图片加边框的3个实用方法
分享3个良心好用的照片加相框工具,个个都是操作简单,还提供了丰富好看的边框模板,瞬间让照片变得有质感,大家可以根据自己的需求选择对应的工具进行添加. 1.改图鸭 一个免费的图片处理网站,提供几十种图片 ...
- html给图片加个框,PS怎么给图片加边框 几个步骤搞定
给自己的的照片弄个精美的边框是非常常见的操作,那么在制作电子相册的过程中,如何用PS来给你的照片加一个好看的边框呢,其实不难,下面就来说一下操作方法,有兴趣的朋友来参考学习下吧. 类别:图像处理 ...
- python 对论文插图制作局部放大图并在原图中相同位置加边框
python 对论文插图制作局部放大图并在原图中相同位置加边框: 全部代码如下: import cv2 import numpy as npimage_path = "E:\\仿真资料\\论 ...
- 如何批量给图片加边框?
不管是在日常工作还是生活学习中,我们经常需要对图片进行处理,比如给图片加上边框,给图片加边框是一项简单的工作,只要使用PS软件就可以帮我们解决问题,相信大部分的小伙伴知道怎么操作,小编就不做详细的介绍 ...
最新文章
- Java的学习之路(1)
- 想要学习Python爬虫,看这几本书就够了
- Vim实战指南(一):基础编辑命令
- 网易干货 | 浅析视频Jitter Buffer
- C# webrequest 抓取数据时,多个域Cookie的问题
- java常用代码_Java 中常用代码 (欢迎补充)
- 漫话:如何给女朋友解释什么是适配器模式?
- python生成指定长度的列表_如何在python中创建固定大小列表?
- three.js glb 多个_奔驰GLB外观完美!内饰酷炫!动力倍儿棒
- 为/tmp添加nodev/nosuid/noexec挂载选项
- 消息映射与消息路由原理
- 外国人聊天常用的缩写(转)
- 拟合函数未知数个数与用于拟合的序列点数的关系
- 【10天企业定制课】2018秋PS软件photoshop/CC应用计划学习视频-孙伟-专题视频课程...
- 文献解读:纵向数据的测量不变性和交叉滞后模型(一)
- 3D测量| 主动模式投影提高AOI三维测量精度
- 嵌入式面试准备一---USART、IIC、SPI、CAN
- 玩转Django2.0---Django笔记建站基础九(一)
- 游戏感:虚拟感觉的游戏设计师指南——第二章 游戏感与人类感知能力
- 双十一买什么比较划算?四款实用性超强不吃灰的数码好物推荐
热门文章
- 2021美赛C题解题记录(内含完整代码)
- matlab图像处理(图像)
- idea git切换分支、拉取最新代码 自己的代码被覆盖怎么办
- PHP工程改成微擎的步骤_微擎系统搭建
- 【379】pandas 说明
- 物理防火墙是什么?有什么作用?
- linux编辑文件发生错误E45: ‘readonly‘ option is set (add ! to override)
- 微信小程序|基于小程序实现打卡功能
- html5离散数学,离散数学怎样判断合取范式和析取范式
- 前端后台常见问题总结