activity_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.bw.lenovo.myapplication.MainActivity">
<com.bw.lenovo.myapplication.CricleView
android:layout_height="match_parent"
android:layout_width="match_parent" />
</RelativeLayout>
CricleView
package com.bw.lenovo.myapplication;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class CricleView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder holder;
private DrawThread thread;
public CricleView(Context context) {
super(context);
init();
}
public CricleView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
holder = getHolder();
holder.addCallback(this);
thread = new DrawThread();
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
thread.start();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
class DrawThread extends Thread{
@Override
public void run() {
super.run();
Paint mPaint = new Paint();
mPaint.setColor(Color.RED);
mPaint.setStrokeWidth(5);
mPaint.setAntiAlias(true);
int radus = 0;
while (true){
if (radus>150) {
radus = 0;
}else {
Canvas canvas = holder.lockCanvas();
radus+=5;
if (canvas!=null){
canvas.drawColor(Color.YELLOW);
canvas.drawCircle(200,200,radus,mPaint);
holder.unlockCanvasAndPost(canvas);
}
}
}
}
}
}
MainActivity
package com.bw.lenovo.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}