Resize items of RecyclerView (ConstraintLayout, Kotlin) - java

I'm working on this app that has a RecyclerView and I want to resize the items so they all can fit within it, without the need of scrolling.
Right now looks like a want because it only has 3 elements, but I need it to be able to show up to 12 (and all of them need to be visible without scrolling!), meaning that if there are 9 elements, those should shrink enough so all of them have the same size and fit within the Recycler.
Is there a way to rescale the items without resizing them manually? I'm about to do it in the Adapter (depending on the itemList.size they will have X or Y padding, margins, etc.). I don't like it at all but I haven't found anything else yet.
I'm using ConstraintLayout and Kotlin.
Thanks a lot!

Related

Is there a way to have a GridView with dynamic cell size?

In android, the gridview provides an excellent way to arrange items neatly. However, the cell size for a grid is fixed. That is, in a 3 column by 4 rows grid, if the very first item is 10 dp in height and the second and third items are 20 dp in height, then all the cells in first row will be of 20 dp height.
I want to find a way where in, the view will automatically adjust the cell size for the first cell, so that items below the first item of 10dp height are displayed immediately below it, instead of leaving that extra 10dp gap.
This is the sort of behaviour we can see in Windows live tiles. The items below small tiles move up to fill the gap. I want to implement a similar functionality.
Is there a way to do that?
So turns out, there was already a way to do this. I just didn't know the right term for it.
Android provides a StaggeredGridLayout Layout Manager that does just what I need.
You can take a look at this page
Also, visit this page to see it in action.

Why do my buttons and other elements keep re-arranging in Android Studio?

I'm building a simple app for a game that has labels, textfields and buttons. Every time I try to run the app the elements on the screen keep moving around in the emulator even if they look find in the editor. Picture of layout
I've tried adjusting them by dragging and dropping and experimenting by changing XML. I think I'm missing something, but is positioning elements on the screen the way you want usually this difficult?
If you use lots of views in vertical direction use Linear layout, if more on horizontal use relative layout as you can position elements left-right or center w.r.t each other or parent easily, use a combination of both to get best results.

Display grid of images in Android with center of grid layout being empty?

I have a decent amount of images(10 or so) that I need to display in grid form with the center of the layout being empty. Currently I'm adding each image through code but that is becoming time consuming. Every image is using the same onTouchListener class. The center of the layout needs to be empty to accommodate a "container" image view that selected images can be dragged and dropped onto. I thought of using an image adapter but only saw examples that were for a gallery type view in either horizontal or vertical orientation. Is there any way to create a custom class that automatically positions the images in grid form with an empty center that has predetermined dimensions?
If you are using a RecyclerView with GridLayoutManager, then you can get the firstVisisbleItem and lastVisibleItem. This should give you the number of visibleItems with which you can decide the index in the grid where you should not show any item. This would require you to take care of some implementation level details, but the basic logic should be like this only. Hope it helps.

How to determine how far a scrollbar has moved in SWT?

Before Scroll
After Scroll
I am working on creating an Eclipse plugin for tracking of collections (Arrays, Array List, etc.). And I was in need of an SWT Table with expandable columns. In order to implement this, I created several SWT buttons, and generated them before I created the table, and I linked them to the columns that need to be expanded. What I'm having a problem with now is that I need a way to determine how much a user scrolled the scroll bar in order to determine what the new location of the buttons should be. For instance, if the user scrolls 10 pixels to the left, I need to move the buttons 10 pixels to the left, etc.
Is there an easy way to accomplish this within the SWT ScrollBar framework?
Actually, I was able to solve the problem by using Scrollbars "getSelection" method. Turns out, the value that this method represents is the offset from 0 of the scrollbar. In order to solve the problem, I just subtracted the getSelection value from the X position of the buttons

Best Way To Fill Screen With Grid of Images

I'm writing an Android app in java that I want to be able to use across all phone screen sizes and resolutions. I need to create a 4x4 array of images (all square and equal in size). I want the images to expand such that they're width is basically the screen width divided by 4.
I first tried a RelativeLayout, but can't figure it out. I figure TableLayout is probably the way to go, but if I just stretch columns, that won't necessarily stretch the images within the cells, right? I need the images to stretch, not just the columns.
Any ideas?
Take a look at this Layout called GridLayout by Romain Guy. You simply addview() your imageviews .Enjoy

Categories

Resources