Basically I want to use SurfaceView for animation. Therefore the class implements Runnable. To experiment, I want to draw a circle. However, it shows only a black screen.
I have been trying for days. Really appreciate if someone can help.
MainActivity class
public class MainActivity extends Activity {
private Bitmap Liquid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature (Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
DrawStripFrame D1 = new DrawStripFrame(this);
setContentView(D1);
DrawStripFrame class
public class DrawStripFrame extends SurfaceView implements Runnable{
private SurfaceHolder holder;
private boolean running = true;
public DrawStripFrame (Context context){
super (context);
holder = getHolder();
}
@Override
public void run(){
while(running){
if(holder.getSurface().isValid()){
Canvas c = holder.lockCanvas();
c.drawARGB(0, 0, 0, 0);
Paint redPaint = new Paint();
redPaint.setColor(Color.RED);
c.drawCircle(100, 100, 30, redPaint);
holder.unlockCanvasAndPost(c);
}
}
}
}
I had this same problem. I tested my APP on different emulators.
This was my MainActivity class
SurfaceViewTest.java
styles.xml
I solved it removing the item background from styles.xml
It looks a problem with the alpha channel.
The problem is solved by changing the while loop like this:
The continue statement sends control back to the top of the loop when surface is invalid. Only when surface is valid, the block below will be executed.