I want to achieve something similar to the attached image
I was thinking of using TableLayout with 2 columns for each row.
There will be padding in order to be apart of each other. Then I will put white background for the cell. Lastly, I'll just add the ImageView and TextView.
The images and text are dynamically generated. I will get the image URL and display them.
So, are there any better or more efficient way for implementing what I want to achieve? TableLayout doesn't seem to be that efficient.
Your diagram looks pretty much like a grid - for which you can use a GridLayout in Android: https://developer.android.com/reference/android/widget/GridLayout.html
A layout that places its children in a rectangular grid.
The grid is composed of a set of infinitely thin lines that separate the viewing area into cells. Throughout the API, grid lines are referenced by grid indices. A grid with N columns has N + 1 grid indices that run from 0 through N inclusive. Regardless of how GridLayout is configured, grid index 0 is fixed to the leading edge of the container and grid index N is fixed to its trailing edge (after padding is taken into account).
Every one of the items in the grid can be a Cardview (https://developer.android.com/training/material/lists-cards.html) - and that way you will also benefit of a consistent look and feel with Android, without much effort.
Take into account that the cards (every item in the grid) will have the same height, tho: How to make a grid layout of CardViews with variable height?.
If the height of the elements will be variable, you should better take a look to the StaggeredGridLayoutManager: https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html
What you have to do is use a RecyclerView with a GridLayoutManager.
For a full working implementation: https://inducesmile.com/android/android-gridlayoutmanager-with-recyclerview-in-material-design/
Related
I have a recyclerview with GridLayoutManager as layout managar and what I want to achieve is like image below
As you can see every row may have multiple item just based on item width and each item is a TextView with wrap_content width but all item have same height.
I know it is possible to set row span by SpanSizeLookup but for doing that, I should know the count of spans before while my list rows will fill just by items width
Can anyone help me?
You might be better off with a different Layout manager like FlexboxLayoutManager https://github.com/google/flexbox-layout
It has lots of flexibility of on controlling when the wrap the row (automatic or manual) and you can specify lots of controls on how individual cells can grow/shrink to fill a line.
There are lots of examples on the github page.
But as a starting point you could manually wrap before cells 3 and 7 to give you the 3 on the first row and 4 on the second.
Or setting FlexWrap will do it automatically based on size
I'm trying to develop a pathfinding app that implements A*.
To begin with, I need to display the navigation cells.
I need to use a single 32 pixel square bitmap that represents the navigation cells in columns and rows (before I load the blocker cells, start point, and end point).
They need to fill the screen in a matrix based on the bitmap width and height - it's ok if it goes off the vertical and horizontal edge.
I'm having trouble determining what type of layout and view to use and how to lay it out.
Any help or a point in the right direction would be appreciated.
This sounds like a straightforward case for using LinearLayouts.
They:
populate vertically and horizontally
can size according to the content
do not scroll
will bleed off the screen
you can dynamically populate them
It should only be one vertical layout and then a series of horizontal layouts. Or one horizontal and then a series of vertical layouts.
A TableLayout might sound appropriate and it could work. But you have to do more work to tell the table how to behave to get results like what you are describing, IMO.
i'm implementing a activity where the user can see images from different sizes and proportions on a GridView. I don't want to modify this images proportions.
Is it possible with GridViews or my best option is to build a TableLayout and just add each image to a TableRow?
Example: If it loads a 3x4 image, i want it to scale to satify some width and height constraint and them merge the necessary GridView's elements to keep the 3x4 proportion rate.
My objective is to reach something like this: https://www.dropbox.com/s/6jmt2x5ly1k2p92/grid.png
It seems you can as a custom gridview, I haven't tested my own, and too low to comment. So on this link you will find an image on the bottom using a gridview notice that the last item is larger that the rest and the middle left item is also off scaled.
I saw this somewhere and was wondering how to achieve this.
suppose i have a shelf background
and i have cover images of books. how can i put those images exactly on each wodden plates edges dynamically.Number of books are not fixed they might go beyond the capacity of shelf then shelf will also grow. Each level of shelf contains maximum 3 cover images of book.
can i do this on background or do i need to draw a shelf on canvas or something else??
Once I tried this kind of UI , There might be several approach , My approach was ,
I had a list view with background as 3D shelf , not like the one which you have shown which has white color wall and other things. Background(3D shelf) which I used to fit entire screen , and space each row of list item exactly to the row of 3D shelf and in list items have 3 buttons with horizontal orientation.
There is already an app called Shelves , Check UI there , it is open source , code there might help you better
http://www.androidpolice.com/2010/08/19/app-of-the-week-shelvescatalogue-your-possessions/
You can achieve it. But you need to be very precise calculation for the width of shelf.
take FrameLayout. Now In this FrameLayout
take ImageView with this shelf image. Add it to FrameLayout
In FrameLayout, take 4 LinearLayouts with horizontal orientation for 4 shelves and adjust its height and left margin exactly as per shelf
add ImageViews of books in those LinearLayouts
I have 6 images I want to display as 2 rows with 3 images in each. I'm using nested LinearLayouts to achieve this, and it works well except for one thing:
The height of the largest image dictates the size of the linear layout, meaning there is empty space a lot of the time. In other words, my problem is as follows:
I keep getting the layout shown on the left, and I want the layout shown on the right.
I am aware that you can just use GridView, but that will still prevent the exact layout shown on the right, so I'm at a loss really. Many thanks.
Instead of 2 rows of three columns, you need 3 columns of 2 rows. LinearLayouts would be fine, just to be sure set the Gravity of the individual cells to Gravity.TOP.
You could equally achieve the whole grid using RelativeLayout instead of Linear. Each of your bottom row would just need android:layout_below and android:layout_alignLeft set to be the ImageView above it.