Android:给图片加边框
1
2
3
4
5
6
7
8
9
|
//设置颜色
public void setColour( int color){
co = color;
}
//设置边框宽度
public void setBorderWidth( int width){
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
|
package xiaosi.imageborder;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
public class ImageBorderActivity extends Activity {
/** Called when the activity is first created. */
private myImageView image = null ;
private myImageView image1 = null ;
@Override
public void 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
|
package xiaosi.imageborder;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.ImageView;
public class myImageView extends ImageView {
private int co;
private int borderwidth;
public myImageView(Context context) {
super (context);
}
public myImageView(Context context, AttributeSet attrs,
int defStyle) {
super (context, attrs, defStyle);
}
public myImageView(Context context, AttributeSet attrs) {
super (context, attrs);
}
//设置颜色
public void setColour( int color){
co = color;
}
//设置边框宽度
public void setBorderWidth( int width){
borderwidth = width;
}
@Override
protected void onDraw(Canvas canvas) {
super .onDraw(canvas);
// 画边框
Rect rec = canvas.getClipBounds();
rec.bottom--;
rec.right--;
Paint paint = new Paint();
//设置边框颜色
paint.setColor(co);
paint.setStyle(Paint.Style.STROKE);
//设置边框宽度
paint.setStrokeWidth(borderwidth);
canvas.drawRect(rec, paint);
}
}
|
Android:给图片加边框相关推荐
- android给图片加边框,android 图片加边框 ImageView border 成效
android 图片加边框 ImageView border 效果 1.布局文件 res/layout/some_page.xml android:id="@+id/respImageBor ...
- android给图片加边框,Android学习笔记进阶19之给图片加边框
//设置颜色 public void setColour(int color){ co = color; } //设置边框宽度 public void setBorderWidth(int width ...
- android 加载进度,Android实现图片加载进度提示
本文实例为大家分享了Android实现图片加载进度提示的具体代码,供大家参考,具体内容如下 先上图: 实现原理: 第一个控件的实现原理是重写ImageView的onDraw()方法,利用Canvas的 ...
- Android Glide图片加载框架(四)回调与监听
文章目录 Android Glide图片加载框架系列文章 Android Glide图片加载框架(一)基本用法 Android Glide图片加载框架(二)源码解析之with() Android Gl ...
- Android Glide图片加载框架(三)缓存机制
文章目录 一.缓存简介 二.缓存用法 内存缓存方式 磁盘缓存方式 三.缓存KEY 四.内存缓存 内存缓存流程 五.磁盘缓存 磁盘缓存流程 Android Glide图片加载框架系列文章 Android ...
- Android Glide图片加载框架(二)源码解析之into()
文章目录 一.前言 二.源码解析 1.into(ImageView) 2.GlideContext.buildImageViewTarget() 3.RequestBuilder.into(Targe ...
- Android Glide图片加载框架(二)源码解析之load()
文章目录 一.前言 二.源码分析 1.load() Android Glide图片加载框架系列文章 Android Glide图片加载框架(一)基本用法 Android Glide图片加载框架(二)源 ...
- Android Glide图片加载框架(二)源码解析之with()
文章目录 一.前言 二.如何阅读源码 三.源码解析 1.with() Android Glide图片加载框架系列文章 Android Glide图片加载框架(一)基本用法 Android Glide图 ...
- Android Glide图片加载框架(一)基本用法
文章目录 一.前言 二.简介 三.基本用法 第一步:调用 Glide.with() 方法创建加载图片的实例 第二步:调用 load() 方法指定待加载的图片资源 第三步:调用 into() 方法绑定显 ...
- 如何给照片加边框?图片加边框的3个实用方法
分享3个良心好用的照片加相框工具,个个都是操作简单,还提供了丰富好看的边框模板,瞬间让照片变得有质感,大家可以根据自己的需求选择对应的工具进行添加. 1.改图鸭 一个免费的图片处理网站,提供几十种图片 ...
最新文章
- 未能加载文件或程序集“AspNetPager”或它的某一个依赖项。拒绝访问。(异常来自 HRESULT:0x80070005 (E_ACCESSDENIED))...
- token、cookie是什么
- idea设置文件多行显示
- python线程检测网段脚本!
- linux fedora yum安装docker-ce
- boost::mpl模块实现pair_view相关的测试程序
- 第17课:RDD案例(join、cogroup等实战)
- 关于Linux的close函数的注意点
- 3 天开发物联网应用!腾讯云 IoT 超级小程序来了
- python输入圆的半径公式_【同步练习】六年级数学上册圆的面积教材同步
- 【C/C++】BOOST 线程完全攻略 - 基础篇
- 验证码的旋转与放缩代码
- 阿里云oss文件分片、断点续传上传
- Solidity语言详解——view和pure函数的使用区别
- MySQL数据库笔记
- [程序员学英语]26个英文字母
- 使用绝热演化/量子退火算法求解矩阵本征态
- Python基础(三)Python容器:列表、元组、字典和集合
- 计算机基础(三)软件
- 《论语》原文及其全文翻译 学而篇9
热门文章
- 最近邻搜索算法flann Marius Muja and David G. Lowe
- idea无法下载源码 Sources not found for: org.springframework:spring-context:5.1.5.RELEAS
- 商务统计_5 用图表演示数据 - 茎叶图
- 第二期:关于大数据相关的问答汇总,关注持续更新中哦~
- php 使用xunsearch--迅搜
- PhD Debate-11 预告 | 矛与盾的对决——神经网络后门攻防
- python中pos函数,python pos是什么
- 移动Web开发字体格式选择(附.woff\.woff2 兼容性)
- 使用GLAD加载OpenGL的库
- 关于华三路由器nat映射ftp端口号登录服务器失败问题