Note that there are some explanatory texts on larger screens.

plurals
  1. POproblems with adding TableRow dynamically vs getMeasuredHeight/getHeight
    primarykey
    data
    text
    <p>I've got a problem. </p> <p>I wish to add rows dynamically to a <code>TableLayout</code>. When adding these rows I need to be able to get the size of the View, so I attempt to perform this during <code>onSizeChanged()</code> but the new rows don't display. So I tried <code>onFinishInflate()</code>, but then I don't have access to the size <code>(getMeasuredHeight returns 0)</code>.</p> <p>Output of the following codes shows two rows <code>initial row</code> + <code>onFinishInflate getMeasuredHeight=0</code>. But if i use hierarchyviewer from the sdk and press <code>load view hierarchy</code> then i suddenly see 3 rows in the emulator <code>initial row</code> + <code>onFinishInflate getMeasuredHeight=0</code> + <code>onSizeChanged getMeasuredHeight=270</code>!.</p> <blockquote> <p>Note: This is using emulator 2.1 hvga landscape, code built with latest sdk, targeting android1.5.</p> </blockquote> <hr> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;com.steelbytes.android.TableHeightTest.TestLinLay xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TableLayout android:id="@+id/table1" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" &gt; &lt;TextView android:text="initial row" /&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; &lt;/com.steelbytes.android.TableHeightTest.TestLinLay&gt; </code></pre> <hr> <pre><code>package com.steelbytes.android.TableHeightTest; import android.app.Activity; import android.os.Bundle; public class TableHeightTest extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } </code></pre> <hr> <pre><code>package com.steelbytes.android.TableHeightTest; import android.content.Context; import android.util.AttributeSet; import android.widget.LinearLayout; import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; public class TestLinLay extends LinearLayout { Context mContext; public TestLinLay(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; } private void addRow(String funcName) { TableLayout tl = (TableLayout)findViewById(R.id.table1); TableRow tr = new TableRow(mContext); TextView tv = new TextView(mContext); tv.setText(funcName+" getMeasuredHeight="+tl.getMeasuredHeight()); tr.addView(tv); tl.addView(tr); } @Override protected void onFinishInflate() { super.onFinishInflate(); addRow("onFinishInflate"); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w,h,oldw,oldh); addRow("onSizeChanged"); } } </code></pre> <hr>
    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