❶ 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); // 取消設置的的劃線