Question

I have a custom view

 abstract public class MyView extends AdapterView<Adapter> implements android.view.View.OnLayoutChangeListener {
     ...
     @Override
     public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
         Log.i("MyView", "onLayoutChange()");
     }
 }

an anonymous subclass of which I instantiate and set as my ContentView during onResume()

onResume() {
    ...
    MyView myView = new MyView(this) {...};
    setContentView(myView);
}

When I now hide the ActionBar and switch to full screen with

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
getActionBar().hide();

the ActionBar and the status bar slowly shrink until they are no longer visible as intended.

Now my MyView would in principle have more space on the screen, but as far as I can tell it is not automatically re-measured and layouted to fill this space.

I would have expected that at least the onLayoutChange() method is called, but I can see with logcat that this is not the case.

What do I need to do in order that onLayoutChange() is called in this situation or how else can I tell my MyView to fill the available space?

Was it helpful?

Solution

Just to give this question an answer (or you can answer it yourself with your own code) ...

As @pskink noted in the comments, don't forget to call addOnLayoutChangeListener.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top