android:stretchColumns - android

I guess I just havent found a good explanation here. So can anyone please tell me what android:stretchColumns actually does? I have it in my table and have tried several different values but cannot seem to figure out what it is doing.
Sorry for the dumb question!

A TableLayout can specify certain columns as shrinkable or stretchable
by calling setColumnShrinkable() or
setColumnStretchable(). If marked as
shrinkable, the column width can be
shrunk to fit the table into its
parent object. If marked as
stretchable, it can expand in width to
fit any extra space. The total width
of the table is defined by its parent
container.
Have a look here, keep in mind that if your table fits nicely ( no space left to stretch) in the parent object, you would not see any changes no matter what value you put in.

Related

Prevent views being pushed off screen

I am trying to have 3 LinearLayouts ordered horizontally (basically forming three columns) within another LinearLayout where the width of the middle layout can vary depending on it's content.
All columns should be visible at all times filling the viewport from left. The left and irght column will be assigned a max width. So only the size of middle layout varies. If the total width of all columns exceeds the viewport size the middle column must not overlap or push out the other columns. But instead it should use the remaining space.
I tried using layout weights but that would put the right column always on the right side and the middle column would fill up all the space even though it's content would not require that.
When I try to use a RelativeLayout as a container I either end up with all three columns overlapping each other or the first column disappears.
I thought the below code (only schematic for now, as I don't have access to the code atm) should work, but as written above the first LinearLayout does not show up. The last LinearLayout seems to be in place as desired.
<RelativeLayout>
<LinearLayout
android:layout_alignParentStart>
</LinearLayout>
<LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_alignParentEnd>
</LinearLayout>
</RelativeLayout>
Does anyone know how I can fix this? Please let me know if you need more detailed code examples etc. I will try to provide them as soon as possible.
I found a few other questions concerning this or similar topics but the solutions always used either layout weights or something like the code snippet above. So far I had no luck with those approaches, maybe because those questions where either for slightly different use cases or a few years old so that the api has changed in the mean time.
Any pointers are greatly appreciated :-)
Yes. You want to defined the center columns with a layout_width="0dp" and a layout_weight="1". The left and right columns will be layout_width="wrap_content".
A LinearLayout should contain the 3 inner "column" LinearLayouts.
I finally found a solution that works.
Using the layout_weight as describe by Jeffrey Blattman alone does only work when the views get large enough to fill the screen.
But as long as the views only fill a part you get gaps between them as the middle view fills up the remaining space. This is something I want to avoid in this case.
For some other reason I had to put my layout into a fragment. Now when I set the dimensions of the fragment to wrap_content the behavior is exactly as I want it. So the views do not get blown up while they are to small but are laid out as if there was no layout_weight defined. But still when growing larger the edge views stay within the screen.

What does android:stretchMode actually do?

I am having an issue with my gridView row height(it is not consistent, it's getting smaller as I scroll down). I was reading other question/answers here and this android:stretchMode is frequently proposed. Since I am new in gridView.
What does android:stretchMode actually do?
According to this documentation from the android developer platform,
android:stretchMode defines how columns should stretch to fill the available empty space, if any.
Must be one of the following constant values.
none Stretching is disabled.
spacingWidth: The spacing between each column is stretched.
columnWidth: Each column is stretched equally.
spacingWidthUniform: The spacing between each column is uniformly stretched..

Android Tablelayout - How to NOT make it fill the parents width?

I'm having some views that display several tables with data. So far so good.
The problem is, the only two ways I can find to size these views is either with a fixed width, which is not what I'm after because the length of the table entries can vary somewhat.
The other is to not specify a width, in which case the table just fills the parent's width by default. Which is also not what I'm after, because then the tables become difficult to read in landscape mode, when the cells become much wider than their content.
All I want is a table that is as wide as it needs to be based on its content, but not wider (and then I'll have to get it centered, but I think I can figure that one out... then again, that's what I always think before finding my head bumping into a simple problem that I thought should be trivial to solve...)
Is there a way to do this, or do I have to write my own table class for that?

Equally space columns with a table layout

When I'm trying to do a neat table layout in android, and try to space the columns equally, all I get is this.
I cannot for the life of me equally space those columns out.
You are using wrong the android:stretchColumns attribute. As you can see in the documentation it is the zero-based index of the column to stretch. So you want to stretch the first column, you should use :
android:stretchColumns="0"
in yout TableLayout.

Table layout only as wide as first image?

I'm building an Android app, and using a TableLayout ViewGroup to display my data.
I would like the TableView to occupy the entire width of the screen, however I'm having trouble getting this to work.
What seems to happen, is the table is only as wide as the widest element in the table, in this case, the image that I put in it.
Here's a screenshot to illustrate the problem.
Additionally, here's the XML source code of my layout.
What specifically should I do to have the layout stretch to the entire width of the screen?
Thanks in advance!
You only have 1 column. Therefore, it should be stretchColumns="0".
Creating a single-column TableLayout is pointless and wasteful. Use a vertical LinearLayout, please. You will probably find that it works better with respect to your problem as a side benefit.
Also, do not repeat the xmlns:android="http://schemas.android.com/apk/res/android" -- it only needs to go on the root element.
BTW, columns are indexed starting from 0, so you are stretching a non-existent column in your existing TableLayout.

Categories

Resources