Android - Gridview or listview? - android

How do i create this kind of views in my application?
(The screenshot is actually of an android application available in android market).
I am confused as i assume that we can create the same kind of layout either by using Gridview or by using ListView.
Problems:
In Gridview, can we give separator between two rows? can we give background to each row in gridview?
In Listview, i think we can customize the listview with 3 books in a row with background, and we can give a separator as well.
From your expert side, please suggest me a possible solution to design and create the same kind of layouts for the android application.

Look at the code of Shelves, written by Romain Guy (one of the ListView's creator).
He used a GridView:
no separator
background is a bitmap drawable
< bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/shelf_panel"
android:tileMode="repeat" />
background image is like this:
The code is worth a look because it contains other interesting solutions, too.

Stated problems:
In Gridview, can we give separator between two rows? can we give background to each row in gridview?
Well, you can always make up a separator by adding something on the bottom of your view. Make it so that it 'connects' on the sides, and you won't know the difference. It will cost you an extra view per grid-item, so probably not the best option.
In Listview, i think we can customize the listview with 3 books in a row with background, and we can give a separator as well.
Eeuhm, yes, although I don't see what the problem is?

With a ListView, each row is counted as an element, so there will be extra work in logic that keeps each item within the row separate. I would suggest you use a gridview. For each grid element, keep an empty shelf space (for one book) as the background image. This image will include the shelf-base. So there is no need for additional rows. The image should look like this:

I would instead suggest to have grid view and view flipper if the number of books are limited.
View flipper will give a better effect than scrolling.

Related

How to make evenly spaced Grid Layout with dynamically added square items

I would like to create a grid layout in which each item is taking as much space as possible (minus padding), but only as long as there are columns available (after that the next item would be inserted in the next row while keeping the size). Additionally, each item must be a square and is added dynamically.
Example layout with 10 items would be as follows:
I have tried to achieve this by setting weights, ratio constraints, overriding onMeasure - but I just can't get it to work. I would be happy with either a programmatic or an XML-based solution (as long as each item can be added programmatically). I would prefer the solution to be in Kotlin, but I would be happy with a Java-based one as well.
It's probably worth saying that each item in the grid layout is a layout (RelativeLayout as of now) to make inflating it and setting a layered background drawable programmatically easy.
I think you might be able achieve what you want with a different Layout
Have a look at https://github.com/google/flexbox-layout it has lots of methods to control how the cells grown or shrink and includes automatic or manual wrapping of cells.
Take a look at RecyclerView. You would need to pass GridLayoutManager. This tutorial may or may not help you. For square items, I suggest using CardView but it's not necessary. If you are targeting tablets as well as smartphones, check this out. And for dynamically adding new items, you should notify recyclerView's adapter. See this link. You can also extend RecyclerView or GridLayoutManager for more control over items.

Android custom layout with different number of childs in row

I have been developing android for a while and I have been facing many similar layouts to the one in screenshot (in both iOS and Android)
So what I would like to achieve is the different number of childs in each row.
Well, first I would like to ask is there a specific name for this layout type, it is not gridview although very close to it.
The structure seems like it can be populated with an adapter since all child buttons look alike
Any help, suggestion, solution or example library is much appreciated.
Taken from Foursquare for Android
Since there is a chance of more than two childs (as you said) therefore what i think is that you can't accommodate so many childs as they would not be visible unless the listview row is horizontally scrollable.......I think you can use gallery widget as an item of listview and then you can have different childs in each row... You can google about the gallery widget, instead of images add your custom layout as gallery item.

Listview, Gridview or something else for single column of scrolling images

re: example http://www.youtube.com/watch?v=Ej--SFh963M
Similar to the above app, I am trying to create a scrolling list of images, like a Listview but with images only. (I also need to set it to fill a set height and width, say 85% of the height, 10% of the width of the screen). Is a one column Griview best? (I have had troubles in the past selecting the image height of a gridview programatically).
Any online tutorials precisely for this you have used?
If your view is going to have only one element per row, then the best and correct way of implementation is to use a ListView. The GridView should or can be used when there are going to be multiple elements per row. I believe the purpose of ListView satisfies its role for your need.
For creating a GridView with uneven rows similar to how Pinterest looks. Includes own OnItemClickListener and OnItemLongClickListener, selector, and fixed position restore. Check out this link, there is a library named "StaggeredGridView" : https://github.com/maurycyw/StaggeredGridViewDemo
As there is no text and only one column of buttons, it seems like I overlooked the obvious answer of using a scrollview of buttons, which is what I will go with. Thanks for your assistance.

create a grid of dots

I would like to create a grid of dots very much like in this game: https://play.google.com/store/apps/details?id=com.nerdyoctopus.gamedots&hl=en
The aim is for each dot to be touchable, so I can recognise where that particular dot is and other information about it.
I don't really know where to start. Do I want to create a custom View for a dot with all the information I want, and then create multiple versions of it? And then do I arrange them in a grid with the setTranslation() method, or would it be better to use LayoutParams with offsets?
If I created my own "Dot" that extended "View", then I could add a lot of different information/methods to it - I could theoretically have a changeColor() method. Is this the best way?
A GridView is not what I am thinking of (as far as I know) as it is basically a different style of ListView.
There are lots of questions here! I have looked at a number of questions here on StackOverflow and elsewhere, but none show/ explain how I should start.
I would use a TableLayout for this. A GridView is the equivalent of a ListView in a 'grid' form, with scrolling, view recycling and whatnot, and that is not what you need. A GridLayout, as Dalmas suggested, would be a much better option if you want to build a static grid, but in my experience it is not easy to distribute the available space equally between columns, and if you are going to need to alter the grid distribution during the game, a TableLayout is much easier to use.
For the dots, yes, a custom view with a configurable color would be the best way to go around it.
You should use a GridLayout. It will do exactly what you need. It is available through the android support library v7 : http://developer.android.com/tools/support-library/features.html#v7-gridlayout
It allows you to arrange views using a grid of rectangular cells.
For the dots, I would go with a custom dot view as you suggest, with a simple method to set the color. Don't store any data in the views if possible, it will make things much easier and flexible.

Best way to create a UI table in Android

I'm trying to design a table UI for my activity. I would like three columns and a fixed number of rows (so that the view fill all allotted space). Each of the cells should be clickable, and able to host standard widgets such as textview of buttons. I also want to control the scrolling (virtual grid with infinite up/down data). Pretty much something like the image below.
What is the recommended way of making a UI like this?
ListView?
TableLayout with dynamically added rows?
Custom class derived from View?
OpenGL?
I tried both 1 & 2, but so far have not been happy (hard to control height of each row). Any comments and code samples welcome.
Your app looks like it works with DB. If so TableLayout is not good to work with things like content providers/ loaders/ CursorAdapter…
Custom view is up to you but I think, based on the image, ListView is good enough. And let it manage the row height itself, that's not a big deal.
I'm not sure about OpenGL. For simple thing, I'd choose ListView/ GridView.

Categories

Resources