title: How to make my toy android calculator UI fits with the device screen
body: <p>I want to create a simple calculator as my first android project (instead of Helloworld), the calculaotr UI is shown below, which I uses <code>GridLayout</code> to arrange the result display <code>TextView</code> and the control <code>Button</code>s, the <code>GridLayout</code> takes 6 rows and 4 columns. ( I simplified the xml layout file here)</p>
  
  <pre><code>&lt;GridLayout android:rowCount="6" 
              android:columnCount="4"
              android:orientation="horizontal"&gt;
      &lt;TextView android:id="@+id/expressionTextView"
                android:layout_columnSpan="4"/&gt;
      &lt;LinearLayout
                android:layout_columnSpan="4"&gt;
          &lt;Button android:id="@+id/btnClearText"/&gt;
          &lt;Button android:id="@+id/btnDeleteText"/&gt;
      &lt;/LinearLayout&gt;
   &lt;GridLayout&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/FNVXJ.jpg" alt="enter image description here"></p>
  
  <p>For creating the <code>+/-/x//0-9.</code> buttons, I use the following code:</p>
  
  <pre><code>String[] buttonTexts = new String[] 
  {
      "7", "8", "9", "/",
      "4", "5", "6", "x",
      "1", "2", "3", "-",
      ".", "0", "=", "+"
  };
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      Point size = new Point();
      getWindowManager().getDefaultDisplay().getSize(size);
      int screenWidth = size.x;
      int screenHeight = size.y;
      int oneQuarterWidth = (int) (screenWidth * 0.25);
  
      for (int ii = 0; ii &lt; buttonTexts.length; ii++) {
          Button btn = new Button(this);
          btn.setText(buttonTexts[ii]);
          btn.setTextSize(40);
  
          GridLayout.Spec rowSpec = GridLayout.spec(ii/4 + 2);
          GridLayout.Spec columnSpec = GridLayout.spec(ii % 4 );
          GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpec, columnSpec);
          params.setGravity(Gravity.FILL);
          params.width = oneQuarterWidth;
          gridLayout.addView(btn, params);
      }
  </code></pre>
  
  <p>However, the last row stretches on the vertical direction, and when running the calculator on my android machine, some of the last row may be hidden!</p>
  
  <p>What I want is to make the UI fits with the device height, do you have any ideas? Thanks!</p>
  
  <p>P.S.
  I even tried to set the heights of the result display <code>TextView</code> and <code>LinearLayout</code> that contains <code>Clear/Del</code> by using:</p>
  
  <pre><code>expressionTextView = (TextView)findViewById(R.id.expressionTextView);
  clearDelLinearLayout = (LinearLayout)findViewById(R.id.linearLayout1);
  
  GridLayout.LayoutParams expressionTextViewParams =
       (GridLayout.LayoutParams)expressionTextView.getLayoutParams();
  expressionTextViewParams.height = ...; // some calculated height
  expressionTextView.setLayoutParams(expressionTextViewParams);
  </code></pre>
  
  <p>But this doesn't work :(</p>