Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I did figure out how to do this. Basically, the part that wasn't working the way I wanted was the TableRows. When I changed to landscape, the first two TableRows weren't resizing at all and the third was consuming the remainder of the space. The fourth row wasn't displaying at all.</p> <p>I figured out that I needed to set the layout_weight of the TableRows to equal values. But, there is no method to do that at runtime, so I built the following layout file, which I called row.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TableRow xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/trow" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"&gt; &lt;/TableRow&gt; </code></pre> <p>Then I used a LayoutInflater to build the row at runtime with the properties I wanted:</p> <pre><code> mTable = (TableLayout)findViewById(R.id.table); LayoutInflater inflater = getLayoutInflater(); for (int j=0; j&lt;4; j++) { View row = inflater.inflate(R.layout.row, mTable,false); TableRow tr = (TableRow)row.findViewById(R.id.trow); for (int i=0; i&lt;4; i++) { View image = inflater.inflate(R.layout.image, tr, false); ImageButton ib = (ImageButton)image.findViewById(R.id.image); ib.setAdjustViewBounds(true); ib.setImageResource(mCardIds[j*4+i]); tr.addView(ib); } mTable.addView(tr); } </code></pre> <p>Now the TableRows are resizing properly on rotation. I changed the ImageViews to ImageButtons because I decided to add some onClick behavior and I am building those buttons via a separate xml file, but I don't think those details are relevant to the resizing issue.</p>
 

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