Programmatically narrow Buttons
<p>I need to dynamically fill tables in my app and when I created the layout in XML I got the right result by messing around and making fields scale, but when I try to do so programatically I get this.</p>

<p><a href="https://i.stack.imgur.com/tikqZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tikqZ.png" alt="The problem"></a></p>

<p>As you can see, the one which got cut off at the bottom was one that still got generated in XML and it matches the title bar perfectly.<br>
The first three are added programmatically and aren't doing what they're supposed to do. </p>

<p>How do I get the Buttons to have no minimum width in code?</p>

<p>This is my row generation function:</p>

<pre><code>private void generateLocationRow(){
    TableLayout tableLocation = (TableLayout) findViewById(R.id.info_table_locations);
    TableRow tableLocationTitleRow = (TableRow) findViewById(R.id.info_table_locations_titles);
    LayoutParams params;
    //create counter for index in table
    int c = 3;
    for(Location l: locations){
        //makes Rows
        TableRow tRow = new TableRow(this);
        tRow.setBackgroundResource(R.color.colorBlueLight);
        tRow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        TableRow tDivider = new TableRow(this);

        //Makes 5 bottomBorders and puts them in an Array
        int bottomBorderCount = tableLocationTitleRow.getChildCount();
        View[] bottomBorders = new View[bottomBorderCount];

        for (int i = 0; i &lt; bottomBorderCount; i++) {
            View bottomBorder = new View(this);
            bottomBorder.setBackgroundResource(R.color.colorDarkGray);
            int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()); //converts dp to px
            bottomBorder.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, height));
            bottomBorder.setLayoutParams(bottomBorder.getLayoutParams());

            bottomBorders[i] = bottomBorder;
        }

        //makes 3 sideBorders and puts them in an Array
        int sideBorderCount = (bottomBorderCount / 2) + (bottomBorderCount % 2);
        View[] sideBorders = new View[sideBorderCount];

        for (int i = 0; i &lt; sideBorderCount; i++){
            View sideBorder = new View(this);
            sideBorder.setBackgroundResource(R.color.colorDarkGray);
            int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()); //converts dp to px
            sideBorder.setLayoutParams(new LayoutParams(width, LayoutParams.FILL_PARENT));
            sideBorder.setLayoutParams(sideBorder.getLayoutParams());

            sideBorders[i] = sideBorder;
        }

        //makes columnInfoButton
        Button btnInfo = new Button(this);
        LayoutParams paramsButton = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT);
        paramsButton.gravity = Gravity.CENTER;
        btnInfo.setPadding(2,2,2,2);
        btnInfo.setMinHeight(0);
        btnInfo.setMinWidth(0);
        btnInfo.setText(R.string.info_button_info);
        btnInfo.setLayoutParams(paramsButton);

        //makes columnType
        TextView txtType = new TextView(this);
        params = new LayoutParams();
        params.setMargins(10, 0, 10, 0);
        params.gravity = Gravity.CENTER;
        txtType.setLayoutParams(params);
        txtType.setPadding(5,5,5,5);
        txtType.setText(String.valueOf(l.getType()));

        //makes columnName
        TextView txtName = new TextView(this);
        txtName.setPadding(5, 5, 5, 5);
        txtName.setLayoutParams(params);
        txtName.setText(String.valueOf(l.getName()));

        //makes columnAddress
        TextView txtAddress = new TextView(this);
        txtAddress.setPadding(5, 5, 5, 5);
        txtAddress.setLayoutParams(params);
        txtAddress.setText(String.valueOf(l.getAddress() + " " + l.getTown()));

        //puts content in TableRow
        tRow.addView(sideBorders[0]);
        tRow.addView(btnInfo);
        tRow.addView(sideBorders[1]);
        tRow.addView(txtType);
        tRow.addView(sideBorders[2]);
        tRow.addView(txtName);
        tRow.addView(sideBorders[3]);
        tRow.addView(txtAddress);
        tRow.addView(sideBorders[4]);

        //makes divider
        for (int i = 0; i &lt; bottomBorderCount; i++){
            tDivider.addView(bottomBorders[i]);
        }

        tableLocation.addView(tRow, c);
        tableLocation.addView(tDivider, c+1);

        c = c+2;
    }
}
</code></pre>

<p>Any help would be appreciated.</p>