Note that there are some explanatory texts on larger screens.

plurals
  1. POSurfaceView not showing animation
    primarykey
    data
    text
    <p>I want to draw an animated picture in my MainActivity My MainActivity code is as follows :</p> <pre><code>public class LaozhangActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { Ch0_1 view=new Ch0_1(this); super.onCreate(savedInstanceState); setContentView(view); } } </code></pre> <p>and I have defined a class that extends <code>SurfaceView</code> in order to show an animated picture; The code is like this: </p> <pre><code>public class Ch0_1 extends SurfaceView implements Callback, Runnable { SurfaceHolder surfaceHolder; private boolean isThreadRunning = true; Canvas canvas; float r = 10; public Ch0_1(Context context) { super(context); surfaceHolder = this.getHolder(); surfaceHolder.addCallback(this); canvas=new Canvas(); } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } public void surfaceCreated(SurfaceHolder holder) { new Thread(this).start(); } public void surfaceDestroyed(SurfaceHolder holder) { } private void Method(int x,int y) { Paint pen=new Paint(); pen.setColor(Color.GREEN); canvas=surfaceHolder.lockCanvas(); canvas.drawLine(0, 0, x, y, pen); surfaceHolder.unlockCanvasAndPost(canvas); } public void run() { while (isThreadRunning) { int x=0,y=0; Method(x,y); try { Thread.sleep(100); } catch (Exception e) { e.printStackTrace(); } x+=10; y+=10; if(x&gt;400)break; } } } </code></pre> <p>When running, the MainActivity is black, it didn't show the picture.<br> Where is the problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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