简体   繁体   中英

Drawing LinearLayout view on canvas disappearing

I'm drawing linearlayout views (insertpoint) on a Surface View Camera using canvas. I'm facing a problem when there are too many views (ex: 40 in my case), some views are disappearing on moving the camera. I'm unable to find the issue here. Is there any issue with the setX and setY method? You can see my code below and please respond to it.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (currentLocation == null) {
        return;
    }

    for (int i = 0; i < places.size(); i++) {
         float[] currentLocationInECEF = LocationHelper.WSG84toECEF(currentLocation);
         float[] pointInECEF = LocationHelper.WSG84toECEF(poiLoc.get(i));
         float[] pointInENU = LocationHelper.ECEFtoENU(currentLocation, currentLocationInECEF, pointInECEF);

        Matrix.multiplyMV(cameraCoordinateVector, 0, rotatedProjectionMatrix, 0, pointInENU, 0);


        if (cameraCoordinateVector[2] < 0 && insertPoint!=null && insertPoint.getChildAt(i)!=null) {
            float x = (0.5f + cameraCoordinateVector[0] / cameraCoordinateVector[3]) * canvas.getWidth();
            float y = (0.5f - cameraCoordinateVector[1] / cameraCoordinateVector[3]) * canvas.getHeight();

            insertPoint.getChildAt(i).setX(x - (insertPoint.getChildAt(i).getWidth()/2));
            insertPoint.getChildAt(i).setY(y);
            insertPoint.getChildAt(i).setVisibility(VISIBLE);
        }
    }
}

Expected result: All the views should appear on the Camera View. Actual Result: Some views are disappearing on moving the Camera and onDrawCanvas callback.

I'm using this library https://github.com/dat-ng/ar-location-based-android

在此处输入图片说明

I have finally managed to fixed the issue. All I had to do is replace LinearLayout with a RelativeLayout and it worked like a charm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM