android two views overlap each other

“setZOrderOnTop” can only be called once before the view is attached to the viewgroup. It cannot be used to change the z level dynamically during the runtime.

If need to alter the z order of two views in a group, “setVisibility” can be called through the UI

runOnUiThread(new Runnable() {
public void run() {

thread to alter the Z order.  for instance, ”

Camera preview failed


Inside SurfaceView Holder, make sure to set the type to SURFACE_TYPE_PUSH_BUFFERS

public void onCreate(Bundle savedInstanceState) {
   // ...
   SurfaceView sur=(SurfaceView)findViewById(;
   SurfaceHolder holder =sur.getHolder();