2-column TableLayout with 50% exactly for each column - android

This one puzzles me since my first steps with Android. I can't make both columns in a 2-column TableLayout exact 50% each.
Here's an example:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<TableLayout
android:id="#+id/tablelayout"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingRight="2dip" >
<TableRow>
<TextView
style="#style/TextViewStandard"
android_layout_span="2"
android:layout_weight="1"
android:text="Bla" />
</TableRow>
<TableRow>
<TextView
style="#style/TextViewStandard"
android:layout_weight="1"
android:text="Name:" />
<EditText
style="#style/EditTextStandard"
android:id="#+id/et_name"
android:layout_weight="1" />
</TableRow>
<TableRow>
<TextView
style="#style/TextViewStandard"
android:layout_weight="1"
android:text="URL:" />
<EditText
style="#style/EditTextStandard"
android:id="#+id/et_url"
android:layout_weight="1" />
</TableRow>
<TableRow>
<Button
style="#style/ButtonStandard"
android:layout_column="0"
android:layout_marginTop="6dip"
android:onClick="onClickOk"
android:text="#android:string/ok" />
</TableRow>
</TableLayout>
</ScrollView>
And here's the corresponding style definition:
<resources>
<style name="ButtonStandard" parent="#android:style/Widget.Button">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
</style>
<style name="EditTextStandard" parent="#android:style/Widget.EditText">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">2dip</item>
<item name="android:layout_marginRight">2dip</item>
<item name="android:layout_marginTop">2dip</item>
<item name="android:layout_width">fill_parent</item>
</style>
<style name="TextViewStandard" parent="#android:style/Widget.TextView">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">2dip</item>
<item name="android:layout_marginRight">2dip</item>
<item name="android:layout_marginTop">2dip</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:textColor">#android:color/white</item>
</style>
</resources>
This becomes really messed up with a CheckBox involved.
What's wrong with my definition?
Many thanks in advance.
HJW

Have you tried to set the android:layout_width attribute to 0dp (and of course keep the android:layout_weight as 1) on the child views?
I have been in similar scenarios when I also wanted to distribute the given space equally between two child views but failed to do so since the child with "wider content" also became wider, within its parent, than its sibling. This was due to the fact that the wider child had a greater initial width. Making sure both children started of from the same width (android:layout_width="0dp" on both of them) also guaranteed to distribute the space evenly among them.

This is how I format my tables evenly. Not part of your question but to span all columns android:layout_span="2" on other TableRow children that do not contain the android:layout_column attribute. Hope this helps.
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView1"
android:layout_column="0">
</TextView>
<TextView
android:id="#+id/textView2"
android:layout_column="1">
</TextView>
</TableRow>
</TableLayout>

I would create a table layout
Inside a frame layout holding your control. In this example I have two columns layout and I put two ImageView's centered in each column.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/button_wedding_day_cheat_sheet"
android:id="#+id/buttonWeddingDayCheatSheet"
android:onClick="onClickWeddingDayCheatSheet"
android:layout_gravity="center_horizontal">
</ImageView>
</FrameLayout>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/button_share_favorite_recipe"
android:id="#+id/buttonShareFavoriteRecipe"
android:onClick="onClickShareFavoriteRecipe"
android:layout_gravity="center_horizontal">
</ImageView>
</FrameLayout>
</TableRow>
</TableLayout>

The columns in the android table always adjust to the widest view which in any row. There are no explicit controls here of the columns. Grid view has more control of the column size such as: android:columnWidth="100dp"
If the left and righ view in the table would be set to the same size then a centered table could have two 50% spaced columns.

Related

View in ConstraintLayout does not fit within screen bounds

I'm trying to align 3 TableLayouts within a ConstraintLayout. I want the table with the MaterialButtons to have 1:1 dimension ratio, while the table on the top and on start still completely remains within the bounds of the screen. This is what it currently looks like:
The definition of this TableLayout:
<TableLayout
android:id="#+id/play_field_table"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/play_field_row_values_table"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.7">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton style="#style/field_unpainted" />
...
<com.google.android.material.button.MaterialButton style="#style/field_unpainted" />
</TableRow>
...
</TableLayout>
The definition of the button's style:
<style name="field_unpainted" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="android:layout_margin">0dp</item>
<item name="android:padding">0dp</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:insetTop">0dp</item>
<item name="android:insetBottom">0dp</item>
<item name="android:textAlignment">center</item>
<item name="android:textStyle">bold</item>
<item name="android:backgroundTint">#ffffff</item>
<item name="android:strokeColor">#000000</item>
<item name="cornerFamily">cut</item>
<item name="cornerRadius">0dp</item>
</style>
The definition of the TableLayout on the start:
<TableLayout
android:id="#+id/play_field_row_values_table"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginLeft="8dp"
app:layout_constraintBottom_toBottomOf="#+id/play_field_table"
app:layout_constraintEnd_toStartOf="#+id/play_field_table"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/play_field_table">
<TableRow
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="end|center_vertical"
android:text="1 1"
android:textAlignment="gravity"
android:textColor="#color/black" />
</TableRow>
...
</TableLayout>
This is the definition of the TableLayout on the top:
<TableLayout
android:id="#+id/play_field_column_values_table"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/play_field_table"
app:layout_constraintEnd_toEndOf="#+id/play_field_table"
app:layout_constraintStart_toStartOf="#+id/play_field_table">
<TableRow
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal|bottom"
android:text="1"
android:textAlignment="gravity"
android:textColor="#color/black" />
...
</TableRow>
...
</TableLayout>
I've tried setting the layout_constraintDimensionRatio to 1:1 on the "id/play_field_table", but then it stretches out of the screen:
Also tried setting the layout_constraintDimensionRatio to 1:1 in the button style, but then the buttons either are just not displayed or the same result as above.
I feel like the ratios should be both set for the buttons and for the table, just can't figure out correct combinations. Any advice?
I managed to fix the issue by setting the following values for the "#+id/play_field_table" TableLayout:
Changed "layout_height" from "wrap_content" to "0dp" value
Added "layout_constraintDimensionRatio" with "1:1" value
Added "layout_weight" with "1" value to the TableRows inside the TableLayout

How to fix visibility="gone" causing stretchColumns in TableLayout to miscalculate widths?

I have a TableLayout embedded within a HorizontalScrollView. Some columns are hidden (android:visibility="gone"). However, even though I have android:stretchColumns="*" on the TableLayout, the columns don't stretch to the full width. Here is what I get:
<-----------------Screen Width---------------->
<---------HorizontalScrollView Width---------->
<---------TableLayout Width------------------->
<---------TableRow Width---------------------->
<-Col1-Col2-Col3-Col4-Col5->
Any ideas on how to fix this? If I physically delete from the XML layout the gone columns (Col6->Col9), then this renders as expected. However, somehow setting the columns to gone has interfered with the stretchColumns.
<HorizontalScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="wrap_content">
<TableLayout
android:stretchColumns="*"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="35dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Col1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Col2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Col3"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Col4"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Col5"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:visibility="gone"
android:text="Col6"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:visibility="gone"
android:text="Col7"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:visibility="gone"
android:text="Col8"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:visibility="gone"
android:text="Col9"/>
</TableRow>
</TableLayout>
</HorizontalScrollView>
Give the TextViews android:layout_weight="1". Better yet, because every one of your TextViews have the same style, just create a style for them in values/styles.xml file like this:
<style name="your_text_view_style">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_height">35dp</item>
</style>
and instead of setting width and height for each view just give them this style in the layout xml.
style="#style/your_text_view_style"

unable to fit text in TableRow in android

I am quite new to android and i am designing a Table layout with every row containing two textviews.The problem is that the text in textview gets truncated if text is long.I have used wrap content and applied weight also but not help me .The code for layout is below
<TableLayout
android:id="#+id/tableLayout"
style="#style/fill_parent_wrap_content" >
<TableRow style="#style/both_wrap_content" >
<TextView
style="#style/InfoTextView1"
android:text="#string/customerName"
android:textStyle="bold" />
<TextView
android:id="#+id/txtDetailCustomerName"
style="#style/InfoTextView1" />
</TableRow>
<TableRow style="#style/both_wrap_content" >
<TextView
style="#style/InfoTextView1"
android:text="#string/caNumberDetail"
android:textStyle="bold" />
<TextView
android:id="#+id/txtDetailCaNo"
style="#style/InfoTextView1" />
</TableRow>
<TableRow style="#style/both_wrap_content" >
<TextView
style="#style/InfoTextView1"
android:text="#string/customerAddress"
android:textStyle="bold" />
<TextView
android:id="#+id/txtDetailAddress"
style="#style/InfoTextView1"
/>
</TableRow>
</TableLayout>
</Scrollview>
This is a style that i apply to textviews
<style name="InfoTextView1">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">5dp</item>
<item name="android:paddingTop">15dp</item>
<item name="android:textColor">#color/Black</item>
<item name="android:textSize">#dimen/text_size_small</item>
</style>
Try this..
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:weightSum="2">
<TextView
android:layout_height="50dp"
android:layout_width="0dp"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"/>
<TextView
android:layout_height="50dp"
android:layout_width="0dp"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"/>
</TableRow>
Then put this line in java file textview.setSelected(true);
Show the style for the TableLayout and TableRows...
I bet the problem is on them.

Centering CheckBox Views

If you're interested in RadioButtons in addition to (or instead of) CheckBoxes, see this question instead.
Despite the presence of
<item name="android:layout_gravity">center_horizontal</item>
in the style file, the two checkboxes are not centered, but appear "left-justified".
res/layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/MyLL"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="#+id/cb1"
style="#style/CB_style" />
<CheckBox
android:id="#+id/cb2"
style="#style/CB_style" />
</LinearLayout>
res/values/styles.xml
<style name="CB_style" parent="#android:style/TextAppearance.Medium">
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
<item name="android:checked">false</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
You have android:layout_weight = 1. So your checkboxes fill all width of screen.
Remove android:layout_weight from style and add margin between checkboxes.
Gravity in Checkbox don't affect the inner tick button, only text.
EDIT
Ok, try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/MyLL"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="5dp"
android:layout_weight="1"/>
<CheckBox
android:id="#+id/cb1"
style="#style/CB_style" />
<TextView
android:layout_width="0dp"
android:layout_height="5dp"
android:layout_weight="1"/>
<CheckBox
android:id="#+id/cb2"
style="#style/CB_style" />
<TextView
android:layout_width="0dp"
android:layout_height="5dp"
android:layout_weight="1"/>
</LinearLayout>
And remove layout_weight from style.
Another way is create custom checkbox. But I think it's too complicated for this problem.
Here's something that may help:
android:gravity vs android:layout_gravity
android:gravity is usually internal, usually asking the view itself what to do with the pixels it has
android:layout_gravity is usually external, usually asking the parent ViewGroup (LinearLayout/RelativeLayout/FrameLayout) how to position the view with extra pixels that the view is not using
If you are using a view with wrap_content, you probably want to use layout_gravity. If you are using a view with match_parent, you probably want to try gravity.
Sometimes wrapping another ViewGroup around a troublesome View can help with positioning. Views and ViewGroups go through an intricate "screen space" negotiating phase, and different Views (Buttons/TextView/ImageView/etc) and ViewGroups (LinearLayout/RelativeLayout/TableLayout/etc) have different rules and negotiating powers
This is why sometimes pairing a troublesome View with another parent like a FrameLayout or LinearLayout can make it behave all of the sudden
This is a little messy but it works, and yes it works as well for 3 or more checkbox inputs:
<LinearLayout
android:padding="0dip"
android:layout_width="0dp"
android:layout_weight="1"
android:hint="name"
android:layout_height="40dip"
android:textAlignment="center" android:layout_gravity="center"
android:orientation="horizontal"
>
<TextView
android:layout_width="0dip"
android:layout_height="1dip" android:layout_weight="1" android:text=" " />
<CheckBox
android:id="#+id/chk1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleX="1.5" android:scaleY="1.5"
>
</CheckBox>
<TextView
android:layout_width="0dip"
android:layout_height="1dip" android:layout_weight="1" android:text=" " />
<CheckBox
android:id="#+id/chk2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleX="1.5" android:scaleY="1.5"
>
</CheckBox>
<TextView
android:layout_width="0dip"
android:layout_height="1dip" android:layout_weight="1" android:text=" " />
</LinearLayout>
Try it in style
<item name="android:layout_width">0dp</item>
I hope it will work.. thanks..
<style name="TextlessCheckBox" parent="android:Widget.Material.CompoundButton.CheckBox">
<item name="android:button">#null</item>
<item name="android:foreground">?android:listChoiceIndicatorMultiple</item>
<item name="android:foregroundGravity">center</item>
</style>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/MyLL"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#ff0000"
android:gravity="center" >
<CheckBox
android:id="#+id/cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#00FF00"
android:gravity="center" >
<CheckBox
android:id="#+id/cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
ok, last try for today ;) you should post a picture next time, HOW it should look... well, now you ll have your LinearLayout divided into two similar wide part (red & green), and in every block your checkbox is in the center...did i got it right this time?!
Just add this to your LinearLayout :
android:gravity="center_horizontal"
This line specifies that anything inside this layout will be in the center.
The Full layout code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<CheckBox
android:id="#+id/cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox ONE"
/>
<CheckBox
android:id="#+id/cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox TWO" />
</LinearLayout>
Here is the output i got :

ImageView expands when displaying an image

I'm trying to make a layout with 10 equal height rows, each row containing an ImageView and a TextView. When I put an image into the ImageView, I would like it scaled to retain the same aspect and fit inside the ImageView, not changing the ImageView size or the height of the containing TableRow.
The problem I have is that when I load an image into the ImageView, the ImageView seems to expand, and it also changes the height of the TableRow (?) I've been looking at this for a while, but can't seem to get it to work. It's possible I have missed one of the details of how Android layout or an ImageView works (?)
I've created a smaller example from my code which exhibits the problem. I've also set the background color on the ImageView so it is easier to see it change size.
Below are my layout files and code (apologies for the formatting, I have also put the complete Eclipse project at http://dl.dropbox.com/u/28937795/ImageRowSample.zip)
Any help would be appreciated. =)
MAIN.XML
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow style="#style/SlashRowStyle">
<ImageView style="#style/SlashViewStyle" />
<TextView style="#style/NumberViewStyle" android:text="0" />
</TableRow>
<TableRow style="#style/SlashRowStyle">
<ImageView style="#style/SlashViewStyle" />
<TextView style="#style/NumberViewStyle" android:text="1" />
</TableRow>
<TableRow style="#style/SlashRowStyle">
<!-- I'm setting the background of this ImageView
so it's easier to see it change size -->
<ImageView android:id="#+id/image2" style="#style/SlashViewStyle"
android:background="#FF0000"/>
<TextView style="#style/NumberViewStyle" android:text="2" />
</TableRow>
<TableRow style="#style/SlashRowStyle">
<ImageView style="#style/SlashViewStyle" />
<TextView style="#style/NumberViewStyle" android:text="3" />
</TableRow>
<TableRow style="#style/SlashRowStyle">
<ImageView style="#style/SlashViewStyle" />
<TextView style="#style/NumberViewStyle" android:text="4" />
</TableRow>
<TableRow style="#style/SlashRowStyle">
<ImageView style="#style/SlashViewStyle" />
<TextView style="#style/NumberViewStyle" android:text="5" />
</TableRow>
<TableRow style="#style/SlashRowStyle">
<ImageView style="#style/SlashViewStyle" />
<TextView style="#style/NumberViewStyle" android:text="6" />
</TableRow>
<TableRow style="#style/SlashRowStyle">
<ImageView style="#style/SlashViewStyle" />
<TextView style="#style/NumberViewStyle" android:text="7" />
</TableRow>
<TableRow style="#style/SlashRowStyle">
<ImageView style="#style/SlashViewStyle" />
<TextView style="#style/NumberViewStyle" android:text="8" />
</TableRow>
<TableRow style="#style/SlashRowStyle">
<ImageView style="#style/SlashViewStyle" />
<TextView style="#style/NumberViewStyle" android:text="9" />
</TableRow>
<LinearLayout style="#style/ButtonBarStyle" >
<Button android:text="Add Image" android:onClick="onClickedAddImage"
android:gravity="center" android:layout_width="0dip"
android:layout_height="fill_parent" android:layout_weight="1" />
<Button android:text="Clear Image" android:onClick="onClickedClearImage"
android:gravity="center" android:layout_width="0dip"
android:layout_height="fill_parent" android:layout_weight="1" />
</LinearLayout>
</TableLayout>
.
STYLES.XML
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="SlashRowStyle" >
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">0dip</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
</style>
<style name="SlashViewStyle" >
<!-- I want scaling so it fits in the Imageview with the same aspect.
I tried both fitCenter and centerInside -->
<item name="android:scaleType">fitCenter</item>
<item name="android:layout_width">0dip</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">40</item>
<item name="android:gravity">center</item>
</style>
<style name="NumberViewStyle">
<item name="android:layout_width">0dip</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">60</item>
<item name="android:gravity">center</item>
<item name="android:typeface">sans</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">20sp</item>
<item name="android:textColor">#0000FF</item>
</style>
<style name="ButtonBarStyle">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">#404040</item>
<item name="android:paddingTop">5dip</item>
</style>
</resources>
.
IMAGEROWSAMPLEACTIVITY.JAVA
public class ImageRowSampleActivity extends Activity {
private ImageView _iv;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_iv = (ImageView)findViewById(R.id.image2);
}
public void onClickedAddImage(View v) {
_iv.setImageResource(R.drawable.x);
}
public void onClickedClearImage(View v) {
//_iv.setImageResource(0); //Tried this also
_iv.setImageDrawable(null);
}
}
After looking at it some more I finally stumbled onto the answer.
The problem is the TableRows in the TableLayout. The Android SDK TableLayout doc says that
The children of a TableLayout cannot specify the layout_width attribute. Width is always
MATCH_PARENT. However, the layout_height attribute can be defined by a child; default value
is WRAP_CONTENT. If the child is a TableRow, then the height is always WRAP_CONTENT.
The TableRow doc also says
The children of a TableRow do not need to specify the layout_width and layout_height
attributes in the XML file. TableRow always enforces those values to be respectively
MATCH_PARENT and WRAP_CONTENT.
So, yeah, the problem was the TableRows always ignoring my settings and making their heights WRAP_CONTENT, then also forcing the ImageView's height to be WRAP_CONTENT. When I converted the TableLayout and TableRows to LinearLayouts with the correct orientations, everything worked as I originally expected...

Categories

Resources