title: How to set size and layout in onSizeChanged?
body: <p>I can't get my elements, for example <code>ListView</code>, to resize properly.</p>
  
  <p>I got a <code>ListActivity</code> for searching, with a dashboard, an editbox and a listview. The idea is to hide the actionbar while the keyboard is showing.</p>
  
  <p>I extended <code>LinearLayout</code>, to listen to view size changes (as recommended <a href="https://stackoverflow.com/questions/3825918/way-to-be-notified-when-the-software-keyboard-is-showing-hiding">here</a>) :</p>
  
  <pre><code>public class SizeChangingLinearLayout extends LinearLayout {
      //...
      @Override
      protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld)
      {        
          View actionbar = mainView.findViewById(R.id.actionbar);
  
          if (yNew &gt; yOld) 
              actionbar.setVisibility(View.VISIBLE);
          else if (yNew &lt; yOld) 
              actionbar.setVisibility(View.GONE);
  
          super.onSizeChanged(xNew, yNew, xOld, yOld);
  
      }
  }
  </code></pre>
  
  <p>The hiding/showing of the actionbar works as expected but there is a gap below the <code>ListView</code> of the same height as the hidden actionbar. As soon as any graphics change (e.g. writing in the editbox) the <code>ListView</code> fills the gap. A similar behavior appears in reverse, when hiding the keyboard.</p>
  
  <p><img src="https://i.stack.imgur.com/yGXLK.png" alt="enter image description here"></p>
  
  <p>[Edit]</p>
  
  <p>The same problem also appears in changing other layout. Changing <code>Visibility</code> of things in <code>onSizeChanged</code> shows directly, but changing sizes and margins does not show until some other user action redraws those views. Invalidation does not work from <code>onSizeChanged</code>.</p>
  
  <p>[/Edit]</p>
  
  <p>I have tried to refresh the graphics by:</p>
  
  <ul>
  <li><code>invalidate</code>-ing both the custom
  LinearLayout and the <code>ListView</code>  (as
  recommended <a href="https://stackoverflow.com/questions/1017853/android-how-to-redraw-a-graphic-element">here</a>)</li>
  <li><code>notifyDataSetChanged</code> on the list's
  adapter</li>
  <li><code>forceLayout</code></li>
  </ul>
  
  <p>... and more, without success. Why is the <code>ListView</code> not resizing at first? Do I have to override <code>onLayout</code> in my extended LinearLayout? What have I missed?</p>