title: Android: Button created in run-time to MATCH_PARENT in Java
body: <p>Hey Everyone, </p>
  
  <pre><code>import android.widget.Button;
  
  @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.webpage);
  
          but_action = new Button(getApplicationContext());
          but_action.setVisibility(Button.INVISIBLE);
          toolbar.addView(but_action);
  </code></pre>
  
  <p>Regarding the code above, this creates an invisible button that i make visible based on some conditions. This works, and so does the logic on the button. </p>
  
  <p>Problem is that the height of the button is static, and this cant be the case. I need this button to simply match its parents height (as you can see its in the toolbar view, which is just a horizontal linearlayout), as the height of the toolbar is different on the tablet sized views as opposed to the phone sized views. </p>
  
  <p>I heard that I need to use LayoutParams, but I will be totally honest: nothing i try validates, and when it does: does nothing. And using setHeight seems to only accept numerical values. </p>
  
  <p>I'm sort of at a roadblock where I'm not sure what else to try. </p>
  
  <p>(also is there something like a float: right; for real-time layout?)</p>