Note that there are some explanatory texts on larger screens.

plurals
  1. POPainting by touchscreen skips (discontiguous lines)
    primarykey
    data
    text
    <p>My Activity Class file:</p> <pre><code>package com.drawing.test; import android.app.Activity; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.LinearLayout; public class TstActivity extends Activity implements OnTouchListener { float x1 = 0, y1 = 0, x2 = 0, y2 = 0; public static boolean action=false; private Bitmap mBitmap; private Canvas mCanvas; private Paint mBitmapPaint; Drawer mDrawer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout mLinearLayout = (LinearLayout) findViewById(R.id.drawView); mLinearLayout.setOnTouchListener((OnTouchListener) this); mLinearLayout.addView(new Drawer(this)); } public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: x1 = event.getX(); y1 = event.getY(); action=false; //v.invalidate(); return true; case MotionEvent.ACTION_MOVE: x1=x2; y1=y2; x2 = event.getX(); y2 = event.getY(); v.invalidate(); action=true; return true; case MotionEvent.ACTION_UP: x2 = event.getX(); y2 = event.getY(); v.invalidate(); action=true; return true; } return false; } public class Drawer extends View { public Drawer(Context context) { super(context); mBitmap = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); mBitmapPaint = new Paint(Paint.DITHER_FLAG); mBitmapPaint.setColor(Color.MAGENTA); invalidate(); } protected void onDraw(Canvas canvas) { if(x1==x2 &amp;&amp; y1==y2)return; Paint p = new Paint(); // Canvas mCanvas1=new Canvas(mBitmap); p.setColor(Color.parseColor("#7CFC00")); canvas.drawBitmap(mBitmap, 0, 0, p); // canvas.drawLine(x1, y1, x2 , y2, p); p.setColor(Color.RED); // mCanvas1.drawLine(x1, y1, x2, y2,p); if(action==true)mCanvas.drawLine(x1, y1, x2, y2, mBitmapPaint); } } } </code></pre> <p>My Layout XML:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/drawView"&gt; &lt;/LinearLayout&gt; </code></pre> <p>When I try this out on emulator, the line breaks in middle but continues drawing. I tried on device too, and same problems happen but lesser in number. Also, the display sometimes flickers, or goes completely blank. When its completely black, it comes back if I touch once.</p> <p>Is there anything wrong that I am doing, shall I change my approach. </p> <p>Any suggestions are appreciated. Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload