Android - How to fit each TableRow to the screen height - android

I'm looking to create a table with 3 cells (TableRow) each cell should have the dimensions of the size of the full screen (width and height).
Should I use something other than a TableLayout to get the same effect?
Thanks a lot.
Here is an example of the expected result

The standard way of doing this will be by using a RecyclerView along with a Vertical Layout Manager, each and every one of your element will have width and height as match parent.

Related

Dynamic height of ImageView in scrollView

I am trying to add 3-4 imageviews in a scroll view. Imageviews have dynamic heights. Height of first view have 70% of the screen and second and third have 30% height. I am using constraint layout and guidelines but the height is getting set according to the height of the scroll view but not according to the screen height. Is there a way to do this with constraint layout.
Have you tried doing it programmatically?
First, get the Screenheight for your device: How to determine the screen width in terms of dp or dip at runtime in Android?
Secondly, get your Imagview and set its height according to xx% of the determined screen height.
BR

Android Layout: Creating a 2x3 grid - trying to avoid nesting LinearLayout with weights

I need to create a 2 by 3 grid, where all the screen space is divided evenly - and I know that nesting linear layouts with weights is bad practice, so I'm looking for an alternative solution.
I need the space to be divided evenly, regardless of screen size - 3 rows with 2 columns each.
From what I understand, GridView/GridLayout/TableLayout will not automatically fill space or divide it evenly - so is there any alternative that will suit my needs?
I know you can set the Layout Params programmatically - is this better practice than using nested LinearLayouts with weights?
Thanks for your help
EDIT: To be clear, I intend to display six images, two in each row with three rows. I simply want to divide the screen space evenly - that is, have three rows of the same height, and two columns in each row of the same width.
EDIT2: This is what I'm using as of now, though I am still interested if someone has a better recommendation. I'm not sure this is better than using nested layout_weight values
In my XML I've weighted 3 LinearLayout containers to each take up 1/3 of the available screen height using layout_weight. (XML has a LinearLayout as it's root element)
Each container as two images as children, for which I'm setting the width programmatically as follows:
//Get appropiate width
DisplayMetrics metrics = con.getResources().getDisplayMetrics();
int width = metrics.widthPixels / 2;
//Set gif views to correct width - half of screen size
teamViewGif1.setLayoutParams(new LinearLayout.LayoutParams(width,LinearLayout.LayoutParams.MATCH_PARENT));
teamViewGif2.setLayoutParams(new LinearLayout.LayoutParams(width,LinearLayout.LayoutParams.MATCH_PARENT));
teamViewGif3.setLayoutParams(new LinearLayout.LayoutParams(width,LinearLayout.LayoutParams.MATCH_PARENT));
teamViewGif4.setLayoutParams(new LinearLayout.LayoutParams(width,LinearLayout.LayoutParams.MATCH_PARENT));
teamViewGif5.setLayoutParams(new LinearLayout.LayoutParams(width,LinearLayout.LayoutParams.MATCH_PARENT));
teamViewGif6.setLayoutParams(new LinearLayout.LayoutParams(width,LinearLayout.LayoutParams.MATCH_PARENT));
Again, I'm still interested if anyone has a better solution or advice
EDIT3: Changed layout to use relative layout instead, and now setting both the images height and width programmatically.

Android - GridLayout cell sizes

I am trying to use GridLayout with ImageViews. My problem is that the images I have are all different sizes. I have set the row count and column count, but somehow I need to set a fixed cell size (somehow uniform - as in cell width = total / num of columns, and cell height = total / num of rows). I want to do this so that when I set height and width of imageview to match_parent, the image view doesn't expand beyond the cell size and the layout looks uniform.
I need 5 rows and 3 columns. Can someone suggest how to do this ?
I answered a similar question here. The theory is to use a wrapper layout for your cell and provide the margins that it needs to it. Then use the imageview inside this layout. Thus the outer layout acts as a container for your imageview and it will never go out of the bound of its parent.

HorrizontalScrollView Full Width

Well, I've developed a HorizontalScrollView with some buttons inside.
I'm able to get the width of this HorizontalScrollView through getWidth(). But that returns the width of the displayed HorizontalScrollView, not the full extension.
How could I get the full width? I mean, the full width including the buttons that are not displayed on the screen?
Cheers.
Your HorizontalScrollView should have only 1 child (a horizontal LinearLayout or something). Try getting the width of that view.

How to make buttons, with dynamic text, the same size and width to height ratio?

I have a few buttons I want to display in a row in a decision tree. I'm trying to get the buttons in each row of the tree to be the same size. But the buttons have different text. Some have a couple words and some have a sentence. Is there a way I can get the buttons to all be the same size and all maintain the same width to height (4:3) ratio?
I can get the heights the same using fill parent on the button heights while having the parent row layout_height set to wrap_content. How can I get the width of the buttons to be the same size while maintaining a 4:3 width to height ratio. (The width to height ratio constraint is so I don't end up with really tall and thin buttons, which would look silly)
Anyone have any suggestions?
Edit:
I just saw this link which is kinda what I am looking for: Scaling layout with invariant aspect ratio in Android
My problem with this is that it will inflate all the buttons and introduce a lot of empty space around the text inside.
If I could find a way to incrementally increase the width or height (whichever is smaller) of the button and then resize it so it re-"wraps_content", then this could work. Anyone know how to re-wrap the content?
If you are able to get the same height for all you can use android:layout_weight="1" for all buttons and put android:layout_width="0dip" so all buttons will have same width

Categories

Resources