0

I've programmed my own custom ViewGroup to be able to display several child views and also dynamically move them around and rotate them. I also combine this custom ViewGroup with a background SurfaceView that is displaying the Camera preview in order to have the Camera Preview as a background all the times.

Everything works fine if I just use my ViewGroup without the Camera SurfaceView, but when I add the Camera SurfaceView I get this strange clipping behaviour as documented in the images. Notice that the clipping only happens if I move or rotate my views, they seem to be unclipped in the original location.

In the following images the blue lines are supposed to be the enclosing rectangle of the child Views that is passed onto the layout method that I call on all the child views of my custom ViewGroup:

public void layout (int l, int t, int r, int b)

http://developer.android.com/reference/android/view/View.html#layout(int, int, int, int)

Don't worry about the red lines.

My hypothesis is that when the ViewGroup is first created it only takes into account the position of the original childviews and this is the space that is reserved for them. And as soon as I rotate them they are clipped to their original rectangle.

270 degrees rotation:

270 Degrees rotation without Camera background

The same with Camera background(the camera does not appear on the screen capture that's why it is also black):

270 Degrees rotation with Camera background

320 degrees rotation:

320 Degrees rotation without Camera background

The same with Camera

320 Degrees rotation with Camera background

0 degrees rotation:

0 Degrees rotation without Camera background

The same with Camera

0 Degrees rotation with Camera background

Here are fragments of the code, I cut a lot of stuff out but this is the very basic functionality(mLayout is my custom ViewGroup):

    public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      requestWindowFeature(Window.FEATURE_NO_TITLE); 
      cPreview = new CameraPreview(this);
      setContentView(cPreview, new ViewGroup.LayoutParams(FILL_PARENT, FILL_PARENT));
      test1();
    }

    private void test1() {
        addContentView(mLayout, new LayoutParams(LayoutParams.FILL_PARENT, 
            LayoutParams.FILL_PARENT));
    }
Roland
  • 7,525
  • 13
  • 61
  • 124
  • Could you post your code/layout? One way to make progress might be to try adding a different view of the same size as your camera view and see what happens. Other places to look: the order in which you are drawing/adding the views, the size of the camera view. – Matthew Feb 25 '11 at 20:49
  • @Matthew I tried it adding a background image instead of the camera. It works fine, no clipping. It seems to be an issue with the SurfaceView. About the code/layout, what exactly do you want to see? My ViewGroup has no static layout because the childviews are dynamically added to it. – Roland Feb 25 '11 at 21:28
  • Maybe you could follow the sample in http://stackoverflow.com/questions/2933882/how-to-draw-an-overlay-on-a-surfaceview-used-by-camera-on-android ? – Matthew Feb 25 '11 at 21:32
  • @Matthew I added a bit of code at the end. – Roland Feb 25 '11 at 21:48

1 Answers1

1

The solution found is to set this flag setWillNotDraw(false) in Your SurfaceView The raison is explained here

Elzouave
  • 11
  • 2