我试图让我的应用程序的用户(用他们的手指)在VideoView对象上绘画。
我收效甚微。
在我目前的尝试中,我尝试将SurfaceView放在VideoView上,虽然我遇到了很多问题:当我打开导航抽屉时,图纸出现在导航抽屉界面上;并且图纸似乎在实际设备上闪烁(它们闪烁)。
这只是我的尝试,我相信有一种更好的方法可以让用户画画。
<VideoView
android:id="@+id/videoplayer"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</VideoView>
<com.example.example.VideoOverlay
android:id="@+id/videooverlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
这是VideoOverlay类
public class VideoOverlay extends SurfaceView implements Runnable {
Thread thread = null;
SurfaceHolder surfaceHolder;
volatile boolean running = false;
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
Random random;
public void onResumeMySurfaceView(){
running = true;
thread = new Thread(this);
thread.start();
}
public void onPauseMySurfaceView(){
boolean retry = true;
running = false;
while(retry){
try {
thread.join();
retry = false;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public VideoOverlay(Context context)
{
super(context);
surfaceHolder = getHolder();
random = new Random();
this.setZOrderMediaOverlay(true);
this.setZOrderOnTop(true);
surfaceHolder.setFormat(PixelFormat.TRANSLUCENT);
}
public VideoOverlay(Context context, AttributeSet attrs)
{
super(context, attrs);
surfaceHolder = getHolder();
random = new Random();
this.setZOrderMediaOverlay(true);
this.setZOrderOnTop(true);
surfaceHolder.setFormat(PixelFormat.TRANSLUCENT);
}
public VideoOverlay(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
surfaceHolder = getHolder();
random = new Random();
this.setZOrderMediaOverlay(true);
this.setZOrderOnTop(true);
surfaceHolder.setFormat(PixelFormat.TRANSLUCENT);
}
// Other stuff
@Override
public void run() {
// TODO Auto-generated method stub
while(running){
if(surfaceHolder.getSurface().isValid()){
Canvas canvas = surfaceHolder.lockCanvas();
//... actual drawing on canvas
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(3);
int w = canvas.getWidth();
int h = canvas.getHeight();
int x = random.nextInt(w-1);
int y = random.nextInt(h-1);
int r = random.nextInt(255);
int g = random.nextInt(255);
int b = random.nextInt(255);
paint.setColor(0xff000000 + (r << 16) + (g << 8) + b);
canvas.drawPoint(x, y, paint);
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
任何帮助都会很棒!