drawable canvas使用
/**
* Drawable 就是一个可画的对象,
* 其可能是一张位图(BitmapDrawable),
* 也可能是一个图形(ShapeDrawable),
* 还有可能是一个图层(LayerDrawable),
* 我们根据画图的需求,创建相应的可画对象
*/
public class DrawTestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
}
class MyView extends View {
private ShapeDrawable shapeDrawable;
private Paint paint;
public MyView(Context context) {
super(context);
shapeDrawable = new ShapeDrawable(new OvalShape());
shapeDrawable.getPaint().setColor(Color.RED);//指定颜色
shapeDrawable.setBounds(10, 10, 200, 100);//指定位置
paint = new Paint();
paint.setColor(Color.BLUE); //颜色
paint.setTextSize(20);//字体大小
paint.setTypeface(Typeface.DEFAULT_BOLD);//粗体字
paint.setAntiAlias(true);//消除锯齿
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//画绿色背景
canvas.drawColor(Color.GREEN);
//画椭圆
shapeDrawable.draw(canvas);//将自己画到画布上
//画文本,坐标是指矩形左下角坐标
canvas.drawText("来自尚硅谷的你, 很NB", 10, 120, paint);
}
}
}
drawable canvas使用的更多相关文章
- 自定义View 实现软键盘实现搜索
1. xml文件中加入自定义 搜索view <com.etoury.etoury.ui.view.IconCenterEditText android:id="@+id/search_ ...
- 安卓开发应该知道的Drawable、Bitmap、Canvas和Paint的关系
首先让我们理解下Android平台中的显示类是View,但是还提供了底层图形类android.graphics,今天所说的这些均为graphics底层图形接口. Bitmap - 称作位图,一般位图的 ...
- Android Drawable 那些不为人知的高效用法
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/43752383,本文出自:[张鸿洋的博客] 1.概述 Drawable在我们平时的 ...
- Android Drawable、Bitmap、byte[]之间的转换
转自http://blog.csdn.net/june5253/article/details/7826597 1.Bitmap-->Drawable Bitmap drawable2Bitma ...
- Android中Bitmap,byte[],Drawable相互转化
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- 【转】Drawable /Bitmap、String/InputStream、Bitmap/byte[]
原文:http://wuxiaolong.me/2015/08/10/Drawable-to-Bitmap/ Drawable互转Bitmap Drawable转Bitmap 1234 Resourc ...
- Android中 Bitmap和Drawable相互转换的方法
1.Drawable->Bitmap Resources res=getResources(); Bitmap bmp=BitmapFactory.decodeResource(res, R.d ...
- Android 2D Graphics学习 Region和Canvas裁剪
1.首先介绍Region类 Region,中文意思即区域的意思,它表示的是canvas图层上的某一块封闭的区域. /**构造方法*/ public Region() //创建一个空的区域 publi ...
- 获取应用图标,Drawable 转bitmap
获取应用图标: PackageManager p = context.getPackageManager(); Drawable draw=null; ApplicationInfo info; tr ...
随机推荐
- 【hash】什么是hash,什么是哈希,什么是hash散列,什么是hash一致性算法【关于hash的详解】
什么是hash,什么是哈希,什么是hash散列,什么是hash一致性算法
- 【前端阅读】——《JavaScript入门经典》摘记之JavaScript与XML
前言:这本书除了基础的JavaScript理论体系之外,有一个特别的章节,就是讲解——JavaScript与XML的关系,从中,我更进一步的了解了XML的基础.创建.显示以及使用JavaScript如 ...
- 第十二题 Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume th ...
- PHP执行linux系统命令
本文是第一篇,讲述如何在PHP中执行系统命令从而实现一些特殊的目的,比如监控服务器负载,重启MySQL.更新SVN.重启Apache等.第二篇<PHP监控linux服务器负载>:http: ...
- struts2获取服务器临时目录
CreateTime--2017年9月7日08:57:39 Author:Marydon struts2获取服务器(tomcat.WebLogic)的临时目录 需要导入: import java. ...
- widget 常用UI控件介绍
一.单选框 单选框实例程序: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...
- 对Date的扩展,将 Date 转化为指定格式的String
<script language="javascript" type="text/javascript"><!-- /** * 对Date的扩 ...
- SQLite可视化管理工具汇总
版权声明:本文为博主原创文章,未经博主允许不得转载. 搜集了一些SQLite工具,在这里做个总结,有的工具用的多一些,有的只是简单试用,甚至未试用,所以有描述不当的还请回复指正,也欢迎补充完善! 20 ...
- HttpClient 模拟登录网易微博
实现核心:代码执行流程,根据抓包工具,模拟浏览器请求步骤走 private static void testLogin() { try ...
- Matlab 绘图全方位分析及源码
Matlab绘图 强大的绘图功能是Matlab的特点之一,Matlab提供了一系列的绘图函数,用户不需要过多的考虑绘图的细节,只需要给出一些基本参数就能得到所需图形,这类函数称为高层绘图函数.此外,M ...