Setting column width in Table View - android

I am having a hard time understanding how to change the width of columns when creating a table view.
I know you can set the width in pixels of a column but that is not what I want to do.
Say, for instance, I have 2 columns and want each column to take up half the screen. How do I do this without explicitly setting the pixels, so that my code can work on multiple screen sizes?

With a TableLayout? You can't do that easily. The closest you can get is to use android:stretchColumns="*" on your TableLayout element. That should allocate any extra whitespace evenly between the two columns.

Just set the TableRow layout_width="0dip"
and then set the two column layout_weight="1"
This will help you evenly divide a row.

Related

Jetpack Compose: How can I align the height of the items of the first column in a row depending on the height of the second column?

I want the items of the first column to stretch their height depending on the total height of the other column in the row.
Now I have it:
And I want it to be like that:
Is this possible without hardcoding the height through calculations?
Use compose arrangement 'equal weight' according to this documentation link
Modifier.weight()

Making buttons take equal height and width of screen

I am currently trying to make a view with four buttons that each take up one quarter of the screen. I know you can use android:layout_weight to set the weight so that the extra space on one axis is filled up, but is there a way to set it so that the height and width are evenly distributed among the four buttons using layout_weight? If not, what is the correct way to do this?
use table layout and create two rows for 4 buttons,determined the height and width
all of these codes are ( XML code)..
should that will working

How to increase the height, width of the table layout?

I wanted to know how to increase the size of the table layout??I have placed the textviews and edittext in table rows that appear on the left side of the screen. I wanted to design similar to this
You can use android:minHeight="60px" or assign the width/height to fill_parent.

How to add the textviews equally in a Row?

i have 5 text views to be added horizontally,and it needs to occupy the displaywidth.When i change the screen orientation,it should change based on it.Is that can be done by Layout or it should be done programmatically
Try using layout_weight parameter. Create a LinearLayout with layout_width="fill_parent" and layout_weightsum="5".
And then add 5 TextViews with layout_width="wrap_content" and layout_weight="1".
You could do that by using android:layout_width="fill_parent" in your text view. This attribute specify that your text views will take up all the parent space in width.
EDIT
Hi..Table layout has a slightly different behaviour.
Quoted from TableLayout:
The width of a column is defined by
the row with the widest cell in that
column. However, 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. It is important to remember
that a column can be both shrinkable
and stretchable. In such a situation,
the column will change its size to
always use up the available space, but
never more. Finally, you can hide a
column by calling
setColumnCollapsed().
The children of a TableLayout cannot
specify the layout_width attribute.
Width is always FILL_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.
hope this helps
EDIT
When stretchable, a column takes up as much as available space as possible in its row
Suppose you have added the five textview in a column at index col_index in your table. This code will stretch the column.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="col_index"
>
...
</TableLayout>

Android Stretch columns evenly in a TableLayout

I am displaying a table of values in my android application, and would like the columns to be distributed evenly in terms of size , instead of sizing according to content.
Been playing around with stretchColumns but couldn't manage to figure out the right combination, Any Ideas?
I had the same problem - I always only entered one number in android:stretchColumns, but you have to enter all columns that should be stretched. So if you have three columns, you have to write:
android:stretchColumns="0,1,2"
Or write:
android:stretchColumns="*"
Then all columns will have the same size. As a reminder, android:stretchColumns is an attribute for the TableLayout element.
You need to set BOTH android:layout_width="0dip" and android:layout_weight="1" for each view within a table row. I think this works because the weights determine the proportion of the EMPTY SPACE in the row used by the respective views, and since the width of all views is set to 0dip, the whole row is empty space, and hence with equal weights the views are all allocated the same proportion of the WHOLE width.
Use the android:layout_weight for the columns
You control the size of the columns by the size of their contents. If you want them all to be the same size, set that up via android:layout_width in the appropriate cells.
Whoever is still looking for solution, for me:
setting columns both shrinkable and stretchable did the trick.
I had pretty much the same problem as OP.

Categories

Resources