发布于 2016-02-18 23:44:07 | 155 次阅读 | 评论: 0 | 来源: 网友投递
Android移动端操作系统
Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。
public class AndroidTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyView mv = new MyView(this);
setContentView(mv);
}
public class MyView extends View {
MyView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
// 首先定义一个paint
Paint paint = new Paint();
// 绘制矩形区域-实心矩形
// 设置颜色
paint.setColor(Color.BLUE);
// 设置样式-填充
paint.setStyle(Style.FILL);
// 绘制一个矩形
canvas.drawRect(new Rect(0, 0, getWidth(), getHeight()), paint);
// 绘空心矩形
// 设置颜色
paint.setColor(Color.RED);
// 设置样式-空心矩形
paint.setStyle(Style.STROKE);
// 绘制一个矩形
canvas.drawRect(new Rect(10, 10, 100, 30), paint);
// 绘文字
// 设置颜色
paint.setColor(Color.GREEN);
// 绘文字
canvas.drawText("Hello", 10, 50, paint);
// 绘图
// 从资源文件中生成位图
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
// 绘图
canvas.drawBitmap(bitmap, 10, 60, paint);
}
}
}