Note that there are some explanatory texts on larger screens.

plurals
  1. POTable doesn't fill the containing layout's width
    primarykey
    data
    text
    <p>I want this table to extend as possible to fill the remaining (empty) area of the linear layout that contains it</p> <p><img src="https://i.stack.imgur.com/9KuEr.png" alt="enter image description here"></p> <p>I generate the table using the following method</p> <pre><code>public void drawTable(LinearLayout tableLayout,String tableTitle, String[][] data,String[] headerTitles, int type){ //clearing previous views tableLayout.setVisibility(View.VISIBLE); tableLayout.setGravity(Gravity.CENTER); int chids = tableLayout.getChildCount(); if (chids &gt; 0){ tableLayout.removeAllViews(); } if((headerTitles!= null) &amp;&amp; (headerTitles.length != data[0].length) ){ return; } TableLayout table = new TableLayout(context); // table.setStretchAllColumns(true); // table.setShrinkAllColumns(true); //Rendering the table title TextView tableTitleView = new TextView(context); tableTitleView.setText(tableTitle); tableTitleView.setTextColor(Color.WHITE); tableTitleView.setGravity(Gravity.CENTER); tableTitleView.setTextSize(18); tableTitleView.setTextAppearance(context, R.style.boldText); tableTitleView.setBackgroundColor(Color.parseColor("#008888")); tableTitleView.setPadding(2, 2, 2, 10); tableLayout.addView(tableTitleView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT)); ScrollView scroll1 = new ScrollView(context); HorizontalScrollView scroll2 = new HorizontalScrollView(context); int rows = data.length; int columns = data[0].length; if(headerTitles!=null){ //Rendering the header TableRow headerRow = new TableRow(context); for (int i = 0; i &lt; columns; i++) { TextView t = new TextView(context); t.setTextSize(17); t.setTextAppearance(context, R.style.boldText); t.setPadding(5, 5, 5, 5); t.setText(headerTitles[i]); t.setGravity(Gravity.CENTER); t.setTextColor(Color.WHITE); t.setBackgroundResource(R.drawable.text_border_header_1); headerRow.addView(t, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); } table.addView(headerRow, new TableLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); } //Rendering the Table Data TableRow row; for (int current = 0; current &lt; rows ; current++) { row = new TableRow(context); TextView t; for(int i =0 ; i &lt; columns ; i++){ t = new TextView(context); t.setTextSize(15); t.setPadding(5,5,5,5); t.setText(data[current][i]); t.setGravity(Gravity.CENTER); if (type == 1) { if (current % 2 == 0) { t.setBackgroundResource(R.drawable.text_border_odd); } else { t.setBackgroundResource(R.drawable.text_border_even); } }else if (type == 2) { if (current % 2 == 0) { t.setBackgroundResource(R.drawable.text_border_odd_2); } else { t.setBackgroundResource(R.drawable.text_border_even_2); } }else if (type == 3) { if (current % 2 == 0) { t.setBackgroundResource(R.drawable.text_border_odd_3); } else { t.setBackgroundResource(R.drawable.text_border_even_3); } } t.setTextColor(Color.BLACK); row.addView(t,TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT); } table.addView(row, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } scroll2.addView(table,LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); scroll1.addView(scroll2,LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); scroll1.setPadding(2, 20, 2, 20); tableLayout.addView(scroll1,LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); } </code></pre> <p>I couldn't figure out exactly the problem with my code.</p> <p><strong>EDIT :</strong></p> <p><strong>when I added the table directly to the linear layout instead of the scroll views the table fits with the linear layout width. It seems that my problem is with the scroll view</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload