1
我正在寫一個簡單的繪圖應用程序。一切都很好,除了繪製時我只能看到它後,我停止觸摸屏幕..我正在繪圖時看不到繪圖?有任何想法嗎?Android繪圖/繪畫應用更新立即?
這裏是onTouchListener:
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
currentDrawingPath = new DrawingPath();
currentDrawingPath.paint = currentPaint;
currentDrawingPath.path = new Path();
currentBrush.mouseDown(currentDrawingPath.path, motionEvent.getX(), motionEvent.getY());
}else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){
currentBrush.mouseMove(currentDrawingPath.path, motionEvent.getX(), motionEvent.getY());
}else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
currentBrush.mouseUp(currentDrawingPath.path, motionEvent.getX(), motionEvent.getY());
drawingSurface.addDrawingPath(currentDrawingPath);
drawingSurface.isDrawing = true;
undoBtn.setEnabled(true);
redoBtn.setEnabled(false);
}
return true;
}
這裏是DrawingPath類:
public class DrawingPath {
public Path path;
public Paint paint;
public void draw(Canvas canvas) {
canvas.drawPath(path, paint);
}
}
這裏是主要的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.meadows.collin.touchtopaint.DrawingSurface
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/drawingSurface" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true">
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="onClick"
android:id="@+id/colorRedBtn"
android:background="@drawable/red_btn" />
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="onClick"
android:id="@+id/colorBlueBtn"
android:background="@drawable/blue_btn" />
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="onClick"
android:id="@+id/colorGreenBtn"
android:background="@drawable/green_btn" />
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="onClick"
android:id="@+id/colorYellowBtn"
android:background="@drawable/yellow_btn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="U"
android:onClick="onClick"
android:id="@+id/undoBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="R"
android:onClick="onClick"
android:id="@+id/redoBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="S"
android:onClick="onClick"
android:id="@+id/saveBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="P"
android:onClick="onClick"
android:id="@+id/pathBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="C"
android:onClick="onClick"
android:id="@+id/circleBtn" />
</LinearLayout>
</RelativeLayout>
沒有工作 – comead
@comead我編輯的職位,希望它有助於 – 2011-12-04 11:37:16
我不挺了解這個。我已經附加了我的主XML文件,mainLayout和newLinearLayout是什麼? – comead