SurfaceView
来源:互联网 发布:阿松为什么被禁 知乎 编辑:程序博客网 时间:2024/06/05 15:23
直接看代码。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.lyj.painter.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<com.lyj.painter.MyView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
package com.lyj.painter;
import java.text.AttributedCharacterIterator.Attribute;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
public class MyView extends SurfaceView implements SurfaceHolder.Callback{
private Paint paint = null;
public MyView(Context context) {
super(context);
paint = new Paint();
paint.setColor(Color.BLACK);
getHolder().addCallback(this);
}
public MyView(Context context,AttributeSet attrs)
{
super(context,attrs);
paint = new Paint();
paint.setColor(Color.BLACK);
getHolder().addCallback(this);
}
public void draw(){
Canvas canvas = getHolder().lockCanvas();//操作之前锁定画布
canvas.drawColor(Color.WHITE);
canvas.drawRect(0, 0, 100, 100, paint);
getHolder().unlockCanvasAndPost(canvas);//绘制完成后解锁画布
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
draw();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
- surfaceview
- SurfaceView
- surfaceview
- surfaceview
- SurfaceView
- SurfaceView
- SurfaceView
- SurfaceView
- SurfaceView
- SurfaceView
- SurfaceView
- surfaceview
- SurfaceView
- SurfaceView
- SurfaceView
- surfaceview
- surfaceview
- SurfaceView
- 黑马程序员——Java中集合学习总结
- CSS3实现的响应式字体:自适应视图窗口大小的新单位
- 关于svn提示版本过旧的处理办法(实际svn版本已是最细)
- 数据存储(NSCoding)
- 明确一下,哪些类型放在data区
- SurfaceView
- Android Studio项目目录结构
- Leetcode #48 Rotate Image
- VFS(虚拟文件系统)
- Entity Framework中数据缓存的问题
- tar.xz文件如何解压
- redis中各种数据类型对应的jedis操作命令
- Dissect Bluedroid From A2DP Part I: Use Case
- UML 基础: 序列图