Android自繪實現步驟

2021-05-25 11:14:07 字數 1532 閱讀 1804

1. 繼承public class myview extends view

2. 實現protected void ondraw(canvas canvas);

int data1=;

canvas.drawcolor(color.white);//設定背景顏色

paint paint= new paint();

paint.setstyle(paint.style.stroke);

paint.setantialias(true);//去鋸齒

paint.setcolor(color.blue);//顏色

paint paint1=new paint();

paint1.setstyle(paint.style.stroke);

paint1.setantialias(true);//去鋸齒

paint1.setcolor(color.dkgray);

//資料 線

int n=1,m=0,x=0;

int nn=1,mm=0,xx=0;

int y=new int[100];

y[0]=120;

for(int x1=0;x1for(int x1=0;x1//設定y軸

canvas.drawline(30, 10, 30, 120, paint);

canvas.drawline(30, 20, 35, 20, paint);

canvas.drawline(30, 40, 35, 40, paint);

canvas.drawline(30, 60, 35, 60, paint);

canvas.drawline(30, 80, 35, 80, paint);

canvas.drawline(30, 100, 35, 100, paint);

//設定x軸

canvas.drawline(30,120,300,120,paint);

canvas.drawline(60, 120, 60, 115, paint);

canvas.drawline(90, 120, 90, 115, paint);

canvas.drawline(120, 120, 120, 115, paint);

canvas.drawline(150, 120, 150, 115, paint);

canvas.drawline(180, 120, 180, 115, paint);

canvas.drawline(210, 120, 210, 115, paint);

canvas.drawline(240, 120, 240, 115, paint);

canvas.drawline(270, 120, 270, 115, paint);

//設定y軸文字

paint.settextsize(7);

canvas.drawtext(getresources().getstring(r.string.str_text1), 5, 100, paint);

}

MFC自繪按鈕的實現

自繪按鈕的實現過程 首先在vc6中新建工程,選擇mfc並且新建dialog工程 在dlg類的物件上新增wm drawitem屬性 新增繪圖函式 void cmy40 mybuttondlg ondrawitem int nidctl,lpdrawitemstruct lpdrawitemstruct...

MFC自繪按鈕的實現

自繪按鈕的實現過程 首先在vc6中新建工程,選擇mfc並且新建dialog工程 輸入工程名,然後將生成的按鈕等刪除,重新新增兩個按鈕。為按鈕設定屬性 選擇自繪,就是自己向上貼圖 在dlg類的物件上新增wm drawitem屬性 在生成的ondrawitem方法中新增如下 新增繪圖函式 void cm...

win32實現ListBox自繪

在createwindowex建立視窗時,需要對引數dwstyle設定上lbs ownerdrawfixed lbs hasstrings這兩個屬性。並且需要在建立listbox視窗的父視窗中處理wm drawitem和wm measureitem兩個訊息進行列表框的重繪。lbs ownerdraw...