在我们的Android应用程序中,我们有一个扩展SurfaceView的自定义类。该应用程序与无人机交互。并且,在扩展SurfaceView的类中,我们需要在视频/摄像机源上绘制圆圈。麻烦的是,如果我们设置setZOrderOnTop(false);,您将看不到圆圈。如果setZOrderOnTop(true);圆圈淹没了所有内容(视图,小部件,按钮,表格布局等),我们希望在圆圈下方绘制圆圈(中间)。调整主XML文件中的顺序绝对没有任何作用。有可能吗?
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_blue"
android:orientation="horizontal"
tools:context=".MainActivity">
<dji.ux.widget.FPVWidget
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!--Other Widgets, Buttons, Table Layout, LineatLayouts, RelativeLayout, Etc.-->
<dji.crc.com.crc.Views.ArcGISOverlay
android:id="@+id/arcGISOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.0"/>
</RelativeLayout>
自定义类:
public class ArcGISOverlay extends SurfaceView {
private SurfaceHolder surfaceHolder;
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private OverlayThread overlayThread = new OverlayThread(this);
private int x = 500;
private int y = 500;
private static ArcGISService arcGISService;
private boolean firstTimeStart = false;
public ArcGISOverlay(Context context) {
super(context);
}
public ArcGISOverlay(Context context, AttributeSet attrs){
super(context, attrs);
setWillNotDraw(false);
arcGISService = new ArcGISService();
init();
}
@Override
protected void onDraw(Canvas canvas){
if (canvas != null){
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
update(canvas);
}
}
public void init(){
surfaceHolder = getHolder();
final ArcGISOverlay arcGISOverlayThread = this;
surfaceHolder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
setZOrderOnTop(true);
surfaceHolder.setFormat(PixelFormat.TRANSPARENT);
if (!overlayThread.isRunning()){
overlayThread.setRunning(true);
overlayThread.start();
}
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
boolean retry = true;
overlayThread.setRunning(false);
while (retry){
try{
overlayThread.join();
overlayThread = new OverlayThread(arcGISOverlayThread);
retry = false;
}
catch(InterruptedException e){
}
}
}
});
}
public void update(Canvas canvas){
if (surfaceHolder.getSurface().isValid()) {
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
Random r = new Random();
for (ArcGISModel model : arcGISService.getViewableData()) {
//draw random circles until the Geo Locations are in the system
canvas.drawCircle(r.nextInt(1800 - 100) + 10, r.nextInt(1500 - 100) + 10, 40, paint);
}
}
}}