Drawing LinearLayout view on canvas disappearing

spykeburn :

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

enter image description here

spykeburn :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=162192&siteId=1