create a grid of dots - android

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.

Related

Xamarin Forms - how to create a Horizontal ListView in xaml?

How to create Horizontal listview that has maximum of 3 row and more column it depends on the data just like in this picture
Link:https://i.stack.imgur.com/cUJjB.jpg
This is my concept don't mind the design i just want to know how to create that kind of list view
You can try FlexLayout.
FlexLayout is similar to the Xamarin.Forms StackLayout in that it can
arrange its children horizontally and vertically in a stack. However,
the FlexLayout is also capable of wrapping its children if there are
too many to fit in a single row or column, and also has many options
for orientation, alignment, and adapting to various screen sizes.
More information can be found in the official documentation.
Set the ItemsPanel of the ListView to a horizontal StackPanel.
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
From this question.
Edit: This solution may actually not work for you. If it doesn't work, take a look at this library. It might help you.

How to make responsive columns

I'm trying to make a dashboard like app to display real time data to a user in a vehicle with a layout similar to the included screenshot. I've tried googling for a direction to follow to try and mimic google's responsive grid columns design principle. However, I can't find any examples of that principle in practice on android. How would I go about implementing this type of design in android? Would you use Grid Layouts?
Ideally I'd like to be able to have a Grid Layout that has cells that are consistent in size that allow me to span a Card View across columns and rows but I don't know of a way to do this using a Grid layout. Any ideas?
Screenshot: https://gyazo.com/912c3414d9e8d46a1fa4eade54d620e6
Take a look at GridLayout. It will allow you to define a grid and to span columns/rows. I was also going to mention GridView, but I don't think that it allows spanning of cells.
Another possibility is FleboxLayout if you need more flexibility. TableLayout also permits spanning.
You can also build a grid layout directly with ConstraintLayout using the "GuideLine" object.
Those are four layouts that I would consider.

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.

GridLayout and dynamic views

I want to use a GridLayout to reproduce a layout similar to what we currently se on the Android Market (I mean Play Store !).
Now I managed to do something relatively similar :
This looks nice, but I do not think this would scale well with many Views if I used bitmaps instead of colors for the backgrounds of the Views. As I understand GridLayout cannot use an adapter, so I would have to manage myself the management of Views when they are shown/hidden.
Any suggestions ? I don't have to use a gridlayout if this layout is possible with another view that I can plug to an adapter.
No there is no magic solution that will auto-populate your views. This is a pretty custom case. Your best bet will be to set a few timers that will periodically load/update the content of each of the sections. You will have to create/destroy/animate all of the views yourself. But I like the idea and glad to see that you are trying to make attractive dynamic content.

Android - Gridview or listview?

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.

Categories

Resources