Creating a custom layout for horizontal buttons with wrapping - android-studio

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.

Related

Make Container Collapse (Fit Content)

I want to make something similar to a modal window, centered vertically and horizontally in the center of the screen. When I put Row or Column in a Container, it wants to expand to fit the screen. I want it to do the opposite. Like have the Container "shrinkwrap" to fit the content of the Column or Row. Is there an attribute I can add to the Container? Or another Widget I can use, that won't blow up, but rather shrink down?
FWIW I come from the HTML/CSS world, and I think this is causing me issues in how I visualize things...

Object's position moves when selecting multiple in fabric.js

If select one object, there is no problem.
However, if you select two or more objects by dragging, the position of is moved as shown on the screen below.
Why is the value of "top" and "left" changing when you make multiple selections?
After trying n-number of solution I figured out the solution to this problem. It was something related to the zoomed canvas. Now it works fine!

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.

No section wrapping in UICollectionView

I am using UICollectionView to display cells but I would like to change the default wrapping behaviour in the sections. I don't want any wrapping, instead, I would like the equivalent of a variable width horizontal scrollview for each section, like shown in the following image.
I can do this using horizontal scrollviews within a vertical scrollview but I would like to use a collection view. Any idea on how to do this with a custom flow layout maybe?
Thanks!
You can nest collection views, but you have to be careful separating their delegates to avoid having one collection view being affected by a call to the other.
Create the first collection view with vertical scrolling and as many sections you like. Its delegate must be the controller view it is embedded in. Subclass its cell.
Inside the first collection view's cell create a second collection view with horizontal scrolling. Its delegate is the cell of the first collection view.
You can find an example here: Issue with nested UICollectionViews

Linearlayout like a "ListView" containing objects in android?

I am making a list using LinearLayout and would like to add several "person"-objects to my "list"
I need to be able to click on an object in this list an pull out the person object or at least the personId to be able to find the specific person in my database.
How do I go about doing this?
I have tried using a TextView but it is too simple to contain all of the desired values.
I have also tried using a ListView but I have several LinearLayout next to each other. The ListView scroll individually and therefore I can't use them
Here is an image:
As you can see I am trying to make a grid of sorts each column is a linearview and at the moment so are each row.
I realize there is a grid but I need to be able to fit objects in where I want them and I am too inexperienced to write my own adapter for the gridview
You can achieve this using a ListView with a custom ArrayAdapter.
Check out this example.
Instead of the Weather class, use your own Person object and make the necessary modifications.
Edit:
After reading your edit, I can see that you have some kind of Grid. So my best guess would be to use a GridView with a custom adapter.
Since you are getting your data from a database, you might as well use a custom CursorAdapter.
But I still haven't figured out what you're trying to do.
It seems that you want all the cells to be visible. That would only mean you have a small/finite amount of cells, and in that case a GridView wouldn't be any better than a for loop that adds views to a layout.

Resources