Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting the layout_weight of the TextView under the TableRow
    primarykey
    data
    text
    <p>This question is actually related to this post <a href="https://stackoverflow.com/questions/3224193/set-the-layout-weight-of-a-textview-programmatically">Set the layout weight of a TextView programmatically</a></p> <p>Based on the answers I just need to set the TextView layout params as follow and set the stretchColumn Property, but by adding the following code to mine, it makes the textView disappear from the Table Layout. </p> <pre><code>TextView tv = new TextView(v.getContext()); tv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); </code></pre> <p>So, here is my code where I want to dynamically add a row with 3 columns with 35%, 5% and 60% weight. Please let me know what is wrong with my code. </p> <pre><code>private void addTableRow(int resIdTitle, String strValue){ TableRow tr = new TableRow(this); // Add First Column TextView tvTitle = new TextView(this); tvTitle.setText(resIdTitle); tvTitle.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.35f)); tr.addView(tvTitle); // Add 2nd Column TextView tvColon = new TextView(this); tvColon.setText(" : "); tvColon.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.05f)); tr.addView(tvColon); // Add the 3rd Column TextView tvValue = new TextView(this); tvValue.setText(strValue); tvValue.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.60f)); tr.addView(tvValue); // Finally add it to the table tl.addView(tr, new TableLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); Log.d(TAG, "Row Added"); } </code></pre> <p>And here is my xml file,</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"&gt; &lt;TableLayout android:id="@+id/tl_cam_get_param" android:layout_width="match_parent" android:layout_height="match_parent" android:title="@string/strGetParamTitle" android:scrollbars="vertical" android:shrinkColumns="0"&gt; &lt;/TableLayout&gt; &lt;/ScrollView&gt; </code></pre> <p>I have also tried setting the layout_width to 0, but still it didn't work. </p> <p>Thanks, <br> artsylar</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.
 

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