編輯:關於Android編程
上一節,實現了畫板的所有功能,包括設置畫筆大小,設置畫筆顏色,橡皮擦等功能,而手寫,也可以添加設置筆跡大小和顏色的功能,這節就順勢實現手寫的調整筆跡大小和調整筆跡的顏色。
先看圖:
其實,手寫和畫板的這些功能都類似,直接復用之前的代碼就行,原理如下:
1. 設置畫筆大小的功能:
1)初始化畫筆。<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+ICAgICAgICAgICAgICAgICAgIDKjqcno1sO7rbHKtcS089ChzqrL+dGh1PG1xLTz0KGhozwvcD4KPHA+ICAgICAgICAgICAgICAgICAgIDOjqdPD0ru49rHkwb+8x9ehtbHHsLutscq1xLTz0KGjrNPD09rU2r340NDG5Mv7stnX97rzu7mxo7PW1q7HsMno1sO1xLutscq089ChoaM8L3A+CjxwPiAgIDwvcD4KPHA+ICAgICAgPHN0cm9uZz4yLiDJ6NbDu62xytHVyau1xLmmxNyjujwvc3Ryb25nPjwvcD4KPHA+PHN0cm9uZz4gICAgICAgICAgICAgIDwvc3Ryb25nPiAgICAgMaOps/XKvLuvu62xyqGjPC9wPgo8cD4gICAgICAgICAgICAgICAgICAgMqOpyejWw7utscq1xNHVyavOqsv50aHU8bXE0dXJq6GjPC9wPgo8cD4gICAgICAgICAgICAgICAgICAgM6Op08PSu7j2seTBv7zH16G1scewu62xyrXE0dXJq6Os08PT2tTavfjQ0Mbky/uy2df3uvO7ubGjs9bWrsewyejWw7XEu62xytHVyauhozwvcD4KPHA+ICAgIDwvcD4KPHA+ICAgICDW99KqtPrC66Oo1NpUb3VjaFZpZXfW0MztvNOjqcjnz8KjujwvcD4KPHByZSBjbGFzcz0="brush:java;">private Paint mPaint; private int currentColor = Color.RED; private int currentSize = 5;
//設置畫筆樣式 public void setPaintStyle(){ mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(currentSize); mPaint.setColor(currentColor); }
設置畫筆大小:
//設置畫筆的大小 public void selectHandWritetSize(int which){ int size =Integer.parseInt(this.getResources().getStringArray(R.array.paintsize)[which]); currentSize = size; setPaintStyle(); }
設置畫筆顏色:
//設置畫筆顏色 public void selectHandWriteColor(int which){ currentColor = paintColor[which]; setPaintStyle(); }
在自定義View中添加這些方法後,接下來就是在Activity中調用這些方法了,同上節(在HandWriteActivity.java中添加如下代碼):
//畫筆大小 case 0: showPaintSizeDialog(view); break; //顏色 case 1: showPaintColorDialog(view); break;
通過點擊這兩個按鈕,彈出對話框,用於選擇畫筆的大小和顏色
showPaintSizeDialog(view),彈出選擇畫筆大小的對話框,如下:
//彈出畫筆大小選項對話框 public void showPaintSizeDialog(View parent){ AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this,R.style.custom_dialog); alertDialogBuilder.setTitle("選擇畫筆大小:"); alertDialogBuilder.setSingleChoiceItems(R.array.paintsize, select_handwrite_size_index, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { select_handwrite_size_index = which; touchView.selectHandWritetSize(which); dialog.dismiss(); } }); alertDialogBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialogBuilder.create().show(); }
showPaintColorDialog(view):彈出顏色選擇對話框,如下:
//彈出畫筆顏色選項對話框 public void showPaintColorDialog(View parent){ AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this,R.style.custom_dialog); alertDialogBuilder.setTitle("選擇畫筆顏色:"); alertDialogBuilder.setSingleChoiceItems(R.array.paintcolor, select_handwrite_color_index, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { select_handwrite_color_index = which; touchView.selectHandWriteColor(which); dialog.dismiss(); } }); alertDialogBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialogBuilder.create().show(); }
裡面同樣也用到了上節提到的arrays.xml
arrays.xml
- @string/track_line
- @string/Eraser
- 5
- 10
- 15
- 20
- 25
- 30
- RED
- BLUE
- BLACK
- GREEN
- YELLOW
- CYAN
- LTGRAY
至此,手寫的功能,也已基本全部完成,接下來就剩將手寫的字保存成文件,並返回保存文件的路徑存儲到數據庫,後續繼續完善。
動畫分類Android動畫有3類:幀動畫、視圖動畫、屬性動畫。幀動畫和視圖動畫又統稱為補間動畫。Android 3.0(API LEVEL 11)開始支持屬性動畫。幀動畫
簡介DancingNumberView是一個用於跳動顯示文本中數字的控件,繼承自TextView.這種控件一般用於顯示金額等對用戶較為敏感的數字,讓UI交互更加生動.它具
1、rk3168_v4.2\frameworks\base\data\videos下面的mp4的拷貝方法! a、其實在我們的原始情況下這個目錄的東西並沒有拷貝到xxx/s
小米電視2s定價在2999很大程度上是小米電視2s功能的刪減,其中大家最為關注的是砍掉了3D功能,3d功能可能不是每個人都需要,但是有總比沒有要好嗎?你說對