alpha 透明度
public class MyDialog extends Dialog { private final View[] keys = new View[9]; private final int[] used;public MyDialog(Context context, int[] used) { super(context); this.used = used; }// Dialog第一次显示时调用onCreate方法; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 设置Dialog的标题和布局文件; setTitle("KeyDialog"); setContentView(R.layout.dialog); // 调用这个方法取得封装的Button控件; findViews(); //遍历整个used数组,得到不可用的数据; for (int i = 0; i < used.length; i++) { if (used[i] != 0) { //根据used得到的数据,把可以用的数据赋值给Button控件, //设置keys数组里的按钮是否可见,INVISIBLE参数为不可见; keys[used[i]-1].setVisibility(View.INVISIBLE); } }}private void findViews() { keys[0] = findViewById(R.id.NO1); keys[1] = findViewById(R.id.NO2); keys[2] = findViewById(R.id.NO3); keys[3] = findViewById(R.id.NO4); keys[4] = findViewById(R.id.NO5); keys[5] = findViewById(R.id.NO6); keys[6] = findViewById(R.id.NO7); keys[7] = findViewById(R.id.NO8); keys[8] = findViewById(R.id.NO9); }} 注意:TableLayout 下的android:stretchColumns属性:设置可伸展的列。该列可以向行方向伸展,最多可占据一整行。控制Dialog的宽度。
//可以分成2大块来看!!! //1、第一块是 创建View,把自定义的布局文件转换成View对象; LayoutInflater layout = LayoutInflater.from(this.getContext()); View layoutView = layout.inflate(R.layout.dialog, null); TextView textView = (TextView) layoutView.findViewById(R.id.textID); textView.setText(sb.toString()); //2、创建Dialog对象并把设置好的View填充进去; AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); builder.setView(layoutView); AlertDialog dialog = builder.create(); dialog.show();
//取出不可用的数据; public int[] getUsedTilesByCoor(int x, int y){ return used[x][y]; } //计算单元格中不可用的数据; public int[] calculateUsedTiles(int x, int y){ int [] c = new int[9]; //计算Y轴方向不可用数据; for(int i = 0; i < 9; i ++){ if( i == y ){ continue; } int t = getTile(x,i); if(t!=0){ c[t-1]=t; } } //计算X轴方向不可用数据: for(int i = 0; i < 9 ; i++){ if(i == x){ continue; } int t = getTile(i,y); if(t != 0){ c[t-1] = t; } } //计算小九宫格不可用数据; int startx = (x / 3) * 3; int starty = (y / 3) * 3; for(int i = startx; i < startx + 3; i++){ for(int j = starty; j < starty + 3; j++){ if(i == x && j == y){ continue; } int t = getTile(i,j); if(t != 0 ){ c[t-1] = t; } } } int nused = 0; for(int t : c){ if(t != 0){ nused ++; } } int [] c1 = new int[nused]; nused = 0 ; for(int t : c){ if(t != 0){ c1[nused++] = t; } } return c1; } //获取屏幕点击的焦点 @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction() != MotionEvent.ACTION_DOWN){ return super.onTouchEvent(event); } int selectedX = (int)(event.getX()/width); int selectedY = (int)(event.getY()/height); int used[] = game.getUsedTilesByCoor(selectedX, selectedY); for(int i = 0 ; i < used.length ; i++){ System.out.println(used[i]); } return true; }
public class Game { private final String str = "360000000004230800000004200"+ "070460003820000014500013020"+ "001900000007048300000000045"; private int [] soduku = new int [9*9]; public Game(){ soduku = fromPuzzleString(str); }// 根据9宫格的坐标,返回坐标的格子中的数据; private int getTile(int x, int y){ return soduku[y* 9 + x]; } public String getTileString(int x, int y){ int v = getTile(x,y); if(v == 0){ return ""; }else{ return String.valueOf(v); } } protected int[] fromPuzzleString(String src){ int[] sudo = new int[str.length()]; for(int i = 0;i < sudo.length;i++){ sudo[i] = str.charAt(i) - '0'; } return sudo; }} //画字体 Paint textpaint = new Paint(); textpaint.setColor(Color.BLACK); textpaint.setStyle(Paint.Style.STROKE); textpaint.setTextSize(height * 0.75f); textpaint.setTextAlign(Paint.Align.CENTER); textpaint.setAntiAlias(true); //计算字体大小 FontMetrics fm = textpaint.getFontMetrics(); float x = width / 2; float y = height / 2 - (fm.ascent + fm.descent)/2; for(int i = 0 ;i < 9 ;i++){ for(int j = 0 ; j < 9 ; j++){ canvas.drawText(new Game().getTileString(i, j), i * width + x,j * height + y, textpaint); } }
Paint paint = new Paint(); paint.setColor(Color.BLACK); // 设置画笔透明度以及RGB属性1、a(透明度)1~255越小越透明 。2、R(红色)0~255越小越淡。3、G(绿色) // 0~255。4、B(蓝色)0~255。 paint.setARGB(200, 5, 100, 230); // 设置抗锯齿 注:设置这个属性后会消耗大量资源,绘制图形时会变慢。 paint.setAntiAlias(true); // 设置画笔的大小,也就是粗细。 paint.setStrokeWidth(1); // 设置画笔的样式。1、STROKE:空心图不填充颜色, paint.setStyle(Style.STROKE); // 绘制矩形,1、左边界的位置,2、上边界的位置,3、有边界的位置,4、下边界的位置。 paint.setTextSize(100); canvas.drawRect(200, 100, 300, 400, paint); // 绘制一条线,前俩个参数是x,y的起始位置的坐标,后俩个是x,y的终止位置的坐标。 canvas.drawLine(100, 100, 400, 400, paint); // 绘制圆形,前两个是圆心 x,y坐标,radius:是圆的半径。 canvas.drawCircle(200, 200, 50, paint); canvas.drawText("appde", 150, 300, paint); canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),300,100,paint); Paint backgroundpaint = new Paint(); backgroundpaint.setColor(getResources().getColor( R.color.BackgroundColor)); canvas.drawRect(0, 0, getWidth(), getHeight(), backgroundpaint);Paint blackpaint = new Paint(); blackpaint.setColor(getResources().getColor(R.color.black));Paint strikingpaint = new Paint(); strikingpaint.setColor(getResources().getColor(R.color.Striking));Paint brightpaint = new Paint(); brightpaint.setColor(getResources().getColor(R.color.Bright));for (int i = 0; i < 9; i++) { canvas.drawLine(0, i * height, getWidth(), i * height, strikingpaint); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, brightpaint); canvas.drawLine(i * width, 0, i * width, getHeight(), strikingpaint); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), brightpaint); } for (int i = 0; i < 9; i++) { if (i % 3 != 0) { continue; } canvas.drawLine(0, i * height, getWidth(), i * height, blackpaint); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, brightpaint); canvas.drawLine(i * width, 0, i * width, getHeight(), blackpaint); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), brightpaint); }Paint textpaint = new Paint(); textpaint.setColor(Color.BLACK); textpaint.setStyle(Paint.Style.STROKE); textpaint.setTextSize(height * 0.75f); textpaint.setTextAlign(Paint.Align.CENTER); float x = width / 2; canvas.drawText("1", 3 * width + x, 61, textpaint);
1、对话框的使用方法 2、自定义对话框的方法 3、在对话框当中显示候选的数字 MyView.java文件:package com.example.shudu03;import android.app.AlertDialog;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.Paint.FontMetrics;import android.view.LayoutInflater;import android.view.MotionEvent;import android.view.View;import android.widget.TextView;public class MyView extends View { public MyView(Context context) { super(context); } private float width; private float height; private Game game=new Game(); @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { this.width=w/9f; this.height=h/9f; super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { //画背景 Paint paintBackgroud=new Paint(); paintBackgroud.setColor(getResources().getColor(R.color.backgroundColor)); canvas.drawRect(0, 0, getWidth(), getHeight(), paintBackgroud); //画第一条颜色重的线的画笔 Paint paintOne=new Paint(); paintOne.setColor(getResources().getColor(R.color.oneLine)); //画第二条颜色轻的线的画笔 Paint paintTwo=new Paint(); paintTwo.setColor(getResources().getColor(R.color.twoLine)); //画颜色重的线 Paint paintThree=new Paint(); paintThree.setColor(getResources().getColor(R.color.threeLine)); for(int i=0;i<9;i++){ canvas.drawLine(0, i*height, getWidth(), i*height, paintOne); canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo); canvas.drawLine(i*width, 0, i*width, getHeight(), paintOne); canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo); } for(int i=0;i<9;i++){ if(i%3 != 0){ continue; } canvas.drawLine(0, i*height, getWidth(), i*height, paintThree); canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo); canvas.drawLine(i*width, 0, i*width, getHeight(),paintThree); canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo); } //画数字的画笔 Paint paintData=new Paint(); paintData.setColor(getResources().getColor(R.color.textColor)); paintData.setStyle(Paint.Style.STROKE); paintData.setTextSize((float) (height*0.75)); paintData.setTextAlign(Paint.Align.CENTER); FontMetrics fm=paintData.getFontMetrics(); float x=width/2; float y=height/2-(fm.ascent+fm.descent)/2; for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ canvas.drawText(game.getTileString(i, j), i*width+x, j*height+y, paintData); } } super.onDraw(canvas); } @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction()!=event.ACTION_DOWN){ return super.onTouchEvent(event); } int selectedx=(int)(event.getX()/width); int selectedy=(int)(event.getY()/height); int used[]=game.getUsedByArray(selectedx, selectedy); StringBuffer result=new StringBuffer(0); for(int i=0; i<used.length;i++){ System.out.println(used[i]); result=result.append(String.valueOf(used[i])); } LayoutInflater layoutInflater=LayoutInflater.from(this.getContext()); View layout=layoutInflater.inflate(R.layout.dialog, null); TextView textView=(TextView)layout.findViewById(R.id.textView1); textView.setText(result); AlertDialog.Builder builder=new AlertDialog.Builder(this.getContext()); builder.setView(layout); AlertDialog alertDialog=builder.create(); alertDialog.show(); return true; } }
1、单点触摸事件 public boolean onTouchEvent(MotionEvent event){ //获取事件的种类 event.getAction(); //获取点击的坐标 event.getX(); event.getY();}2、碰撞检测通用方法:检测用户点击的位置,判断这个点击点是否在矩形框内?判断用户点击的位置在具体哪个格子里??点击的点得坐标除以高度,宽度,得到在哪一个单元格里3可用数据计算源代码:Game.java文件:package com.example.shudu03;public class Game { private final String str="360000000"+"004230800" +"000004200"+"070460003"+"820000014"+"500013020" +"001900000"+"007048300"+"000000045"; private int shuduku[]=new int[9*9]; //用于存储每个单元格已经不可用的数据 private int used[][][]=new int[9][9][]; public Game() { shuduku=formPuzzleString(str); getAllUsed(); } //根据九宫格的坐标,返回该坐标所引该填写数据 private int getTile(int x,int y){ return shuduku[y*9+x]; } //将九宫格坐标的数字转化为String类型 public String getTileString(int x,int y){ int v=getTile(x,y); if(v==0){ return ""; } else{ return String.valueOf(v); } } protected int[] formPuzzleString(String str){ int[] shudu=new int[str.length()]; for(int i=0;i<shudu.length;i++){ shudu[i]=str.charAt(i)-'0'; } return shudu; } //得到某个单元格已经用过的数据 public int[] getUsed(int x,int y){ int c[]=new int[9]; for(int i=0;i<9;i++){ if(i==x){ continue; } int t=getTile(x,i); if(t!=0){ c[t-1]=t; } } for(int i=0;i<9;i++){ if(i==x){ continue; } int t=getTile(i,y); if(t!=0){ c[t-1]=t; } } int startx=(x/3)*3; int starty=(y/3)*3; for(int i=startx;i<startx;i++){ for(int j=starty;j<starty+3;j++){ if(i==x&&j==y){ continue; } int t=getTile(i,j); if(t!=0){ c[t-1]=t; } } } int rused=0; for(int i:c){ if(i!=0) rused++; } int c1[]=new int[rused]; rused=0; for(int j:c){ if(j!=0){ c1[rused++]=j; } } return c1; } //得到每一个单元格已经用过的数据 public void getAllUsed(){ for(int x=0;x<9;x++){ for(int y=0;y<9;y++){ used[x][y]=getUsed(x,y); } } } //根据used数组得到某个单元格已经用过的数据 public int[] getUsedByArray(int x,int y){ return used[x][y]; }}MyView.java文件:package com.example.shudu03;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.Paint.FontMetrics;import android.view.MotionEvent;import android.view.View;public class MyView extends View { public MyView(Context context) { super(context); } private float width; private float height; private Game game=new Game(); @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { this.width=w/9f; this.height=h/9f; super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { //画背景 Paint paintBackgroud=new Paint(); paintBackgroud.setColor(getResources().getColor(R.color.backgroundColor)); canvas.drawRect(0, 0, getWidth(), getHeight(), paintBackgroud); //画第一条颜色重的线的画笔 Paint paintOne=new Paint(); paintOne.setColor(getResources().getColor(R.color.oneLine)); //画第二条颜色轻的线的画笔 Paint paintTwo=new Paint(); paintTwo.setColor(getResources().getColor(R.color.twoLine)); //画颜色重的线 Paint paintThree=new Paint(); paintThree.setColor(getResources().getColor(R.color.threeLine)); for(int i=0;i<9;i++){ canvas.drawLine(0, i*height, getWidth(), i*height, paintOne); canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo); canvas.drawLine(i*width, 0, i*width, getHeight(), paintOne); canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo); } for(int i=0;i<9;i++){ if(i%3 != 0){ continue; } canvas.drawLine(0, i*height, getWidth(), i*height, paintThree); canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo); canvas.drawLine(i*width, 0, i*width, getHeight(),paintThree); canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo); } //画数字的画笔 Paint paintData=new Paint(); paintData.setColor(getResources().getColor(R.color.textColor)); paintData.setStyle(Paint.Style.STROKE); paintData.setTextSize((float) (height*0.75)); paintData.setTextAlign(Paint.Align.CENTER); FontMetrics fm=paintData.getFontMetrics(); float x=width/2; float y=height/2-(fm.ascent+fm.descent)/2; for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ canvas.drawText(game.getTileString(i, j), i*width+x, j*height+y, paintData); } } super.onDraw(canvas); } @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction()!=event.ACTION_DOWN){ return super.onTouchEvent(event); } int selectedx=(int)(event.getX()/width); int selectedy=(int)(event.getY()/height); int used[]=game.getUsedByArray(selectedx, selectedy); for(int i=0; i<used.length;i++) System.out.println(used[i]); return true; } }
1、FontMetrics的使用方法FontMetrics fm=paint.getFontMetrics();top:baseLine到字符框的最顶端的高度,是负数bottom:baseLine到字符框的最低端的高度,是正数ascent:baseLine到字符视觉最顶端的高度,是负数descent:baseLine到字符视觉最顶端的高度,是正数(ascent+descent)/2 关键代码:float x=width/2; float y=height/2 - (ascent+descent)/2Game.java文件:package com.example.shudu03;public class Game { private final String str="360000000"+"004230800" +"000004200"+"070460003"+"820000014"+"500013020" +"001900000"+"007048300"+"000000045"; private int shuduku[]=new int[9*9]; public Game() { shuduku=formPuzzleString(str); } //根据九宫格的坐标,返回该坐标所引该填写数据 private int getTile(int x,int y){ return shuduku[y*9+x]; } //将九宫格坐标的数字转化为String类型 public String getTileString(int x,int y){ int v=getTile(x,y); if(v==0){ return ""; } else{ return String.valueOf(v); } } protected int[] formPuzzleString(String str){ int[] shudu=new int[str.length()]; for(int i=0;i<shudu.length;i++){ shudu[i]=str.charAt(i)-'0'; } return shudu; }}MyView.java文件:package com.example.shudu03;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.Paint.FontMetrics;import android.view.View;public class MyView extends View { public MyView(Context context) { super(context); } private float width; private float height; private Game game=new Game(); @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { this.width=w/9f; this.height=h/9f; super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { //画背景 Paint paintBackgroud=new Paint(); paintBackgroud.setColor(getResources().getColor(R.color.backgroundColor)); canvas.drawRect(0, 0, getWidth(), getHeight(), paintBackgroud); //画第一条颜色重的线的画笔 Paint paintOne=new Paint(); paintOne.setColor(getResources().getColor(R.color.oneLine)); //画第二条颜色轻的线的画笔 Paint paintTwo=new Paint(); paintTwo.setColor(getResources().getColor(R.color.twoLine)); //画颜色重的线 Paint paintThree=new Paint(); paintThree.setColor(getResources().getColor(R.color.threeLine)); for(int i=0;i<9;i++){ canvas.drawLine(0, i*height, getWidth(), i*height, paintOne); canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo); canvas.drawLine(i*width, 0, i*width, getHeight(), paintOne); canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo); } for(int i=0;i<9;i++){ if(i%3 != 0){ continue; } canvas.drawLine(0, i*height, getWidth(), i*height, paintThree); canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo); canvas.drawLine(i*width, 0, i*width, getHeight(),paintThree); canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo); } //画数字的画笔 Paint paintData=new Paint(); paintData.setColor(getResources().getColor(R.color.textColor)); paintData.setStyle(Paint.Style.STROKE); paintData.setTextSize((float) (height*0.75)); paintData.setTextAlign(Paint.Align.CENTER); FontMetrics fm=paintData.getFontMetrics(); float x=width/2; float y=height/2-(fm.ascent+fm.descent)/2; for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ canvas.drawText(game.getTileString(i, j), i*width+x, j*height+y, paintData); } } super.onDraw(canvas); } }
1、绘制九宫格2、在九宫格中放置数字MyView.java文件:package com.example.shudu03;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.view.View;public class MyView extends View { public MyView(Context context) { super(context); } private float width; private float height; @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { this.width=w/9f; this.height=h/9f; super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { //画背景 Paint paintBackgroud=new Paint(); paintBackgroud.setColor(getResources().getColor(R.color.backgroundColor)); canvas.drawRect(0, 0, getWidth(), getHeight(), paintBackgroud); //画第一条颜色重的线的画笔 Paint paintOne=new Paint(); paintOne.setColor(getResources().getColor(R.color.oneLine)); //画第二条颜色轻的线的画笔 Paint paintTwo=new Paint(); paintTwo.setColor(getResources().getColor(R.color.twoLine)); //画横竖三条颜色重的线 Paint paintThree=new Paint(); paintThree.setColor(getResources().getColor(R.color.threeLine)); for(int i=0;i<9;i++){ canvas.drawLine(0, i*height, getWidth(), i*height, paintOne); canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo); canvas.drawLine(i*width, 0, i*width, getHeight(), paintOne); canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo); } for(int i=0;i<9;i++){ if(i%3 != 0){ continue; } canvas.drawLine(0, i*height, getWidth(), i*height, paintThree); canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo); canvas.drawLine(i*width, 0, i*width, getHeight(),paintThree); canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo); } //画数字的画笔 Paint paintData=new Paint(); paintData.setColor(getResources().getColor(R.color.textColor)); paintData.setStyle(Paint.Style.STROKE); paintData.setTextSize((float) (height*0.75)); paintData.setTextAlign(Paint.Align.CENTER); float x=width/2; canvas.drawText("1", 3*width+x, 61, paintData); super.onDraw(canvas); } }color.xml文件:<?xml version="1.0" encoding="utf-8"?><resources> <color name="backgroundColor">#ffe2e5e7</color> <color name="textColor">#ff252525</color> <color name="oneLine">#ffeceff0</color> <color name="twoLine">#fffbfbfb</color> <color name="threeLine">#ff858585</color></resources>MainActivity.java文件:package com.example.shudu03;import android.os.Bundle;import android.app.Activity;import android.view.Menu;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);// setContentView(R.layout.activity_main); setContentView(new MyView(this)); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }}
1、Paint的设置方法setAntiAlias:设置画笔的锯齿效果setColor:设置画笔颜色setARGB:设置画笔的a、r、g、b值,接受整形参数。setAlpha:设置Alpha值setTextSize:设置字体尺寸setStyle:设置画笔风格,空心或者实心setStrokeWidth:设置空心的边框宽度getColor:得到画笔的颜色getAlpha:得到画笔的Alpha值2、使用Canvas绘制点、线和图形绘制直线:drawLine(float startX, float startY, float stopX, float stopY, Paint paint)绘制矩形:drawRect(float left, float top, float right, float bottom, Paint paint)绘制圆形:drawCircle(float cx, float cy, float radius, Paint paint)3、使用Canvas绘制文字drawText(String text, float x, float y, Paint paint)4、使用Canvas绘制图片的方法drawBitmap(Bitmap bitmap, float left, float top, Paint paint )相应的代码如下:canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),100, 400, paint);
1.数独,日本人发明2.Android图形编程:颜色color,画笔paint,画布canvas对象3.Color静态方法argb(int,int,int,int),a透明度,rgb三原色4.程序中的颜色多次使用时可用XML页面定义5. 自定义view:定义一个类继承view,重写onDraw方法,在onDraw中用Canvas,Paint对象绘制图形6.View是所有控件类的父类,绘制View时都是调用onDraw方法, 具体使用Canvas,Pain
Android图形编程基本概念1.颜色对象2.画笔对象3.画布对象
Android图形编辑基本概念1、颜色对象2、画笔对象3、画布对象Android 系统当中颜色的表示方法:1、int color1 = Color.blue(blue是一个int)2、int Color2 = Color.argb(1)【a是透明度,r是红色,g绿的浓度,b蓝色浓度】3、在xml文件当中定义颜色;Paint画笔该类的对象用于控制画笔的风格(粗细等等)和颜色等方面的信息;例如:paint.setColor(Color.blue);Canvas画布该类代表一块画布,可以在画布上绘制字符、图片和图形等等内容。例如:canvas.drawCircle(300,400,100,paint);如何自定义View的基本实现方法Button、TextView、等等是一个View;1、定义一个类,继承View;2、复写View的onDraw函数。3、在onDraw当中使用Canvas和Paint对象绘制图形。如何自定义View以及如何在onDraw中画出来。视频实在太不清楚了。。代码看不清楚。。
1 为数字按钮绑定监听器2 刷新九宫格显示3 更新备选数字数组
1 实现Dialog类的方法2 为用户显示备选数字
1 对话框的使用方法AlertDialog.Builder2 自定义对话框的方法 3 在对话框中显示候选数字
1 单点触摸事件onTouchEvent(MotionEvent event)2 碰撞检测 3 可用数据计算
1 FontMetrics的使用方法FontMetrics fm = paint.getFontMetrics();top,bottom包括留白ascent、descent不包括留白top和ascent值是负数2 文字在矩形框中的居中方法设置画笔在水平方向居中利用FontMetrcs中的数据,在垂直方向居中。baseline居中后向下移动(ascent-descent)/23 初始化九宫格数据Game类,游戏逻辑。
练习课1 绘制九宫格背景-浅蓝细线加深颜色的线 2 在九宫格当中放置数字根据小格子的左顶点绘制数字 代码shuduViewMainActivitycolor.xml