❶ android设计中如何随机生成一个方格界面,类似于棋盘那种,用什么函数实现
public class MainActivity 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);
}
private int startX = 0; //起始位置
private int startY = 0;
private int GRID_WIDTH = 30; //格子的高和宽
private int GRID_NUM = 12;//要画的棋盘中的线数
Paint paint = new Paint();//定义画笔
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
paint.setColor(0xffff0000);//设置画笔的颜色
paint.setAntiAlias(true);//去锯齿
for(int i=0;i<GRID_NUM;i++)
{
//画横线
canvas.drawLine(startX, startY+i*GRID_WIDTH,startX+(GRID_NUM-1)*GRID_WIDTH , startY+i*GRID_WIDTH, paint);
//画纵线
canvas.drawLine(startX+i*GRID_WIDTH, startY,startX+i*GRID_WIDTH , startY+(GRID_NUM-1)*GRID_WIDTH, paint);
}
}
}
}
我已经尽力来……
❷ android 怎么画2层圆环
Android绘制两层圆环,可以使用自定义View,继承View,重写里面的Ondraw方法,花两个同心圆,示例如下:
java">packagecom.cn.myvn;
importandroid.content.Context;
importandroid.graphics.Canvas;
importandroid.graphics.Paint;
importandroid.util.AttributeSet;
importandroid.view.View;
{
privatefinalPaintpaint;
privatefinalContextcontext;
publicRingView(Contextcontext){
//TODOAuto-generatedconstructorstub
this(context,null);
}
publicRingView(Contextcontext,AttributeSetattrs){
super(context,attrs);
//TODOAuto-generatedconstructorstub
this.context=context;
this.paint=newPaint();
this.paint.setAntiAlias(true);//消除锯齿
this.paint.setStyle(Paint.Style.STROKE);//绘制空心圆
}
@Override
protectedvoidonDraw(Canvascanvas){
//TODOAuto-generatedmethodstub
intcenter=getWidth()/2;
intinnerCircle=dip2px(context,83);//设置内圆半径
intringWidth=dip2px(context,5);//设置圆环宽度
//绘制内圆
this.paint.setARGB(155,167,190,206);
this.paint.setStrokeWidth(2);
canvas.drawCircle(center,center,innerCircle,this.paint);
//绘制圆环
this.paint.setARGB(255,212,225,233);
this.paint.setStrokeWidth(ringWidth);
canvas.drawCircle(center,center,innerCircle+1+ringWidth/2,this.paint);
//绘制外圆
this.paint.setARGB(155,167,190,206);
this.paint.setStrokeWidth(2);
canvas.drawCircle(center,center,innerCircle+ringWidth,this.paint);
super.onDraw(canvas);
}
}
❸ Android 如何在数字上加一条横线,求代码,哪位大牛帮下忙啊
这要要在代码中设置
textView.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG ); //下划线
textView.getPaint().setAntiAlias(true);//抗锯齿
textview.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG); //中划线
setFlags(Paint. STRIKE_THRU_TEXT_FLAG|Paint.ANTI_ALIAS_FLAG); // 设置中划线并加清晰
textView.getPaint().setFlags(0); // 取消设置的的划线