GridLayout, GridView, RecyclerView... for a 2x8 and 4x8 grid - android-layout

I want to make two seperate grids, one with 2 columns and 8 rows and another with 4 columns and 8 rows. Which layout should I choose? It only needs to work vertically and there should be some space on the top for a button. I don't want any elements to disappear, but I would also prefer not to scroll to see all elements.

You can use a GridLayoutManager instead of a LinearLayoutManager when you set the RecyclerView up.
recyclerView.setLayoutManager(new GridLayoutManager(this, numberOfColumns));
Also, this tutorial will provide you further detail https://www.android-examples.com/android-recyclerview-with-gridview-gridlayoutmanager/.

Related

Creating a custom layout for horizontal buttons with wrapping

I wasn't sure what to title this without explaining it all there. Essentially, I want to populate part of a screen with a bunch of buttons. The buttons should have text from an ArrayList (or other structure) and they should be aligned horizontally to each other from the left to the right of the screen. When there is no more room to the right, it starts a new row. I've attached an example. Example layout here
I know how to make custom list adapters for my objects and how to make listeners for parts within the list items, but I'm just not sure how to make the "list" of buttons go horizontally with wrapping to the next line.
It seems https://github.com/google/flexbox-layout might help you.
You can use FlexboxLayoutManager as adapter, or simply place all the buttons inside FlexboxLayout, they will wrap automatically depending on their width.

How to align the button horizontally and vertically in Document?

I want to align the button horizontally and vertically in Document, i now ho to align horizontally, but i can`t undestand how to align vertically?
In picture bellow, button align horizontal, but how align vertically, in option button i don`t find something about align vertically.
Vertical align is possible in tables only.
Create a table with one row and one column. Set wanted height as "Minimum height" and "Vertically align" to "Center". Content will be centered vertically this way.
I know, it is just a workaround, but it works. Of course, set "Cell Border Thickness" all to 0 so table border is invisible.
If those are 2 buttons, why don’t you just put a ‘return’ (CR) between them. The 2 buttons will be positioned one below the other.
If need be, you can size the buttons, so they have the same width via the properties.
There is no option to "fit to window" vertically in normaal Notes form and document display. It assumes an infinitely long document consisting of paragraphs.
There is, however, the option of displaying a document using the #DialogBox formula or the NotesUIWorkpace.DialogBox method. Both of those have an auto vertical fit argument that you can provide. This will likely require you to redesign your application a bit, but I think it's the only way to do what you want.

TableWrapData: widgets won't left align properly

My program uses TableWrapLayout with numColumns set to 2. I then have the following code: (background colors are set to show you that the widgets aren't using the blank space).
Label label = toolkit.createLabel(container, "Resource Type":);
label.setLayoutData(new TableWrapData(TableWrapData.LEFT,TableWrapData.MIDDLE));
label.setBackground(DiagramSettings.NODE_BACKGROUND_COLOR);
resourceComboMenu = new Combo(container, SWT.READ_ONLY);
resourceComboMenu.setBackground(DiagramSettings.NODE_BACKGROUND_COLOR);
resourceComboMenu.setLayoutData(new TableWrapData(TableWrapData.LEFT,TableWrapData.MIDDLE));
However as you can see in the picture the combo box refuses to left align properly. But that I mean I want it to start right after the label, not have a bunch of blank space.
One workaround would be to put the row inside it's own Composite just like I do Resource Icon and Geolocation. But I feel like I shouldn't need to since the widgets on this row equals the number of columns set by the layout. I've created this workaround for now but would like to understand this TableWrapData behavior for the future.
Any insight would be helpful, thanks.
I pretty much answered my question in the question. The composite that contains everything in the picture had TableWrapData with columns set to 2. TableWrapData essentially draws a straight, vertical line between each column then makes sure widgets from one column don't cross it.
So to fix this (like I mentioned in my question) you simply make another composite with nested widgets (which in the case would be the resource type label and resourceComboMenu). I just didn't realize that is what you're supposed to do.

Android centering listview items

My problem is that i need to center verticaly items in listview. I have 3 items. I've tried to use
layout_center_vertical="true"
but it doesn't work. What do i need to do?

Which android layout to use for distributing variable width buttons to fill a screen?

I am getting started with Android, trying to write a "concentration" game for kids where a screen full of text is separated into buttons, filling the screen (one word per button)
The buttons should wrap to the contained text, so longer words will have longer button widths.
Once a row fills up, the next button should flow to the next row, and so on, until the whole screen is filled with evenly spaced variable width buttons.
The number of rows and number of buttons per row varies based on screen size (and as mentioned, button width)
I could use a vertical linear layout, then insert horizontal linear layouts to contain the row text. However I don't see how to make those widths and number of rows vary based on the screen size and text size.
I presume I need to create my own custom layout, something like FlowLayout in Spring - if so, can you recommend a tutorial for how to do so?
Check android's API Demos
Animation->DefaultLayoutAnimation (for example)
LayoutAnimationsByDefault.java & layout_animations_by_default.xml (for source)
It uses GridLayout and with a bit of modifications of mentioned example, it will be useful for your case..It's flexible, it's available since API Level 14, but it's available trought support/compatibility library or 3rd party library .
Hope this will help.. Cheers ;)

Resources