8种机械键盘轴体对比
本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?
ImageViewtask1Iv.setImageResource(R.mipmap.task1);## SurfaceView ##final Paint paint = new Paint();
final Rect rect = new Rect();
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.task1);
SurfaceHolder surfaceHolder = surfaceViewTask1.getHolder();
surfaceHolder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
surfaceViewTask1.getGlobalVisibleRect(rect);
int measuredWidth = surfaceViewTask1.getMeasuredWidth();
int width = rect.right - rect.left;
Log.e("ccc",measuredWidth+"----"+width);
Surface surface = holder.getSurface();
Canvas canvas = surface.lockCanvas(rect);
canvas.drawBitmap(bitmap,null,rect,paint);
surface.unlockCanvasAndPost(canvas);
surface.release();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
});### 扩展surfaceView显示倒计时功能 ###public class Task1CustomSurfaceView extends SurfaceView implements SurfaceHolder.Callback{
private MyThread mThread;
public Task1CustomSurfaceView(Context context) {
this(context,null);
}
public Task1CustomSurfaceView(Context context, AttributeSet attrs) {
this(context, attrs,0);
}
public Task1CustomSurfaceView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
SurfaceHolder holder = getHolder();
holder.addCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mThread = new MyThread(holder);
mThread.start();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
class MyThread extends Thread{
private Paint mPaint = new Paint();
private SurfaceHolder mHolder;
private DisplayMetrics displayMetrics;
MyThread(SurfaceHolder holder){
this.mHolder = holder;
displayMetrics = getResources().getDisplayMetrics();
}
@Override
public void run() {
try{
for(int i = 0; i<30;i++){ canvas="" canvas.drawcolor(color.white);="" mpaint.setcolor(color.gray);="" mpaint.settextsize(typedvalue.applydimension(typedvalue.complex_unit_sp,16,displaymetrics));="" canvas.drawtext("倒计时:"+(30-i),50,50,mpaint);="" mholder.unlockcanvasandpost(canvas);="" thread.sleep(1000);="" }="" }catch="" (exception="" e){="" <="" pre="">
## 自定义view的方式 ###
public class MyCustomViewForTask1 extends View{
public MyCustomViewForTask1(Context context) {
this(context,null);
}
public MyCustomViewForTask1(Context context,AttributeSet attrs) {
super(context, attrs,0);
}
public MyCustomViewForTask1(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.task1);
canvas.drawBitmap(bitmap,0,0,new Paint());
}
}