Hello, I was facing this issue myself this morning. 
My problem was with a custom dialog in which I had a dynamically filled 
TableLayout inside a ScrollView (all inside this dialog). Each row of the 
TableLayout has an image on the left (which uses at most 64x64 dip) and some 
text on the right.
What I had to do was to set the gravity to CENTER_VERTICAL for *both *table 
row as well as the textview to make sure that the text was correctly aligned 
with the image.

This is the relevant XML:

[...]

    <ScrollView android:id="@+id/tableScrollView"
        android:maxLines="10"
        android:layout_width="wrap_content" 
android:layout_height="match_parent">
        <TableLayout android:id="@+id/dynamicTableLayout"
            android:layout_width="fill_parent" 
android:layout_height="fill_parent">
            <TableRow android:id="@+id/dynamicTableRow01" 
android:layout_width="fill_parent"
                android:layout_height="wrap_content">
            </TableRow>
        </TableLayout>
    </ScrollView>

[...]


This is the Java code in which I add each row:
(to get a reference to that TableLayout you must call findViewById() from 
the dialog object as that method can only help you find a child of the view 
object you are calling it from)

[...]

        /* Create a new row to be added. */
        TableRow tr = new TableRow(this);
        tr.setLayoutParams(new TableRow.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        tr.setGravity(Gravity.CENTER_VERTICAL); //the TableRow must be 
centered properly for the text in the text view
                                                //to be correctly aligned to 
the image view
        
        /* Add an image to the row-content. */
        ImageView img = new ImageView(this);
        img.setAdjustViewBounds(true);
        img.setMaxWidth(64);
        img.setMaxHeight(64);
        img.setLayoutParams(new LayoutParams(
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        
        Bitmap bmp = BitmapFactory.decodeFile(image_file);
        if (bmp == null) {
            //default image
        }
        else {
            img.setImageBitmap(bmp);
        }
        tr.addView(img);
        
        TextView textRow = new TextView(this);
        textRow.setSingleLine(true);
        textRow.setGravity(Gravity.CENTER_VERTICAL);
        textRow.setLayoutParams(new LayoutParams(
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        textRow.setText(msgString);
        
        tr.addView(textRow);
        tl.addView(tr);

[...]

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to