2011-12-03 14 views
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クラスです:

<?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> 

答えて

1

は引き分けを使用してみてください(キャンバス:ここ

public class DrawingPath { 
    public Path path; 
    public Paint paint; 

    public void draw(Canvas canvas) { 
     canvas.drawPath(path, paint); 
    } 
} 

は、メインのXMLファイルです。キャンバス)MotionEvent.ACTION_MOVEの場合

私がやったことをここで

、すべての動きテストされ、結果は(描画)を示した:

private LinearLayout ll1; 
private FrameLayout layout; 

private float xAxis = 0; 
private float yAxis = 0; 

private LinearLayout newLinearLayout; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    layout = (FrameLayout) findViewById(R.id.LinearLayout01); 

    ll1 = (LinearLayout) findViewById(R.id.ll); 
    newLinearLayout = ll1; 

    ll1.setOnTouchListener(this); 
} 

public void redraw() { 
    mainLayout.removeAllViews(); 

    newLinearLayout.setPadding((int) xAxis, (int) yAxis, 0, 0); 

    mainLayout.addView(newLinearLayout); 

} 

@Override 
public boolean onTouch(View v, MotionEvent event) { 
    switch (event.getAction()) { 
    case MotionEvent.ACTION_MOVE: 
     xAxis = event.getX(); 
     yAxis = event.getY(); 
     redraw(); 

    case MotionEvent.ACTION_UP: 
     System.out.println("intermediate finished"); 

    } 
    return true; 
} 

をXML:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center" > 

    <LinearLayout 
     android:id="@+id/ll" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Testing" /> 
    </LinearLayout> 

</FrameLayout> 
+0

私はポストを編集した作品 – comead

+0

@comeadをdidntの、それは私はかなりいけない –

+0

を役に立てば幸いこれを理解します。メインXMLファイルを添付していますが、mainLayoutとnewLinearLayoutではどうですか? – comead

関連する問題