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.
Related
I want to implement a schedule-like overview as List and as Grid View. Currently this works using a RecyclerView and swapping out the LayoutManager at Runtime. This works fine in general, but as soon as I tuned the grid cells to have a fixed height, I realised that the RecyclerView does not respect the wrap_content layout property and instead introduces whitespace between my grid items.
I then stumbled over more or less the same question for the linear LayoutManager and the third-party provided specialisations of the LayoutManager. A quick searched revealed nothing similar for the GridLayoutManager and I am beginning to suspect I am going down the wrong road:
Apart from the easy switching between layouts, there seems to be no reason for me to work with a recycler view:
I dont't require any special animation stuff.
My adapter returns a fixed list without loading more items on demand.
Actual recycling of items doesn't even take place.
So I am currently evaluating to simply switch to separate Fragments using an ordinary ListView and GridView. But this does feel a little like working against the intentions of Android ... After all, they introduced a single view that (in theory) should exactly do what I need.
Am I missing something obvious that could turn out to be painful when using those "legacy" Views to get the job done? Or are there maybe other, more specific Views that allow switching from linear to grid layouts apart from the RecyclerView?
If this should be of importance: I am using Xamarin.Android, not native Java. But I would be willing to port some code from Java to C#.
Follow this ticket:
https://code.google.com/p/android/issues/detail?id=74772
It is not merged yet but soon should be merged and WRAP_CONTENT support should be available in the next version (23.1.1+) or the one after.
I could use some help with merging multiple views into one, like Pinterest has at
I know how to make a reusable custom view, been searching around custom components, compound controls, checked sdk samples and threads like Custom view made of multiple views , but it was never the proper way. I want it to also show 1 view (where i can set the image/texts dynamically) at the hierarchy viewer instead of 5+ child subviews, as that way increases performance aswell. I checked the github acc of Pinterest too without success :)
Can I somehow achieve it, or Im way too off? Thanks!
Try creating a separate layout.xml file containing all of the views you want to have in your custom view. Then in java all you would have to do is make reference to each of those custom views and fill them with your data.
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.
Suppose I have a list of data to be displayed. I know how to display it using a ListView And it is very simple and easy to do it that way. But I am looking for an alternative way to achieve the same. I don't expect to have more than 20 items in the data set I am planning for.
I was thinking of a number of squares that the user can swipe to see the next one etc, similar to some widgets on home screen.
I came across android.widget.StackView, any advice available for this?
You can try StackView (http://developer.android.com/reference/android/widget/StackView.html).
This is how the Gallery and Youtube widgets are rendered.
ListView is the best option for listing lots of data. It has very efficient loading property. But if you do not want it any specific reason, you have to use ScrollView and in ScrollView, you have to place a LinearLayout and in that LinearLayout, you have to place multiple LinearLayout(for each items of data).
Maybe you can use a ViewPager (available also for lower versions of SDK through compatibility pack).
http://developer.android.com/training/implementing-navigation/lateral.html - see also the project example top right of the page : EffectiveNavigation.zip
You can use a GridView, if you want to show multiple items on a page in a different fashion than in ListView.
You can also use ViewPager (from android 3.0, or with the support library) with your custom views.
They both inherit ViewAnimator. I know that ViewSwitcher allows only two views, while ViewFlipper allows more. But why did Android create ViewSwitcher, if it is just a ViewFlipper with 2 views? Are there any other differences? On what condition will be using the one superior than the other?
From what I can tell, ViewSwitcher is used if you want to switch between two views like you said. Useful if you have 2 views that you have to go back and forth fairly regularly. And the class implements a ViewFactory if you wish to use it.
However, ViewFlipper can be used if you want to periodically change the views. Say like an automated flipping book of some sort. Though a custom-adapter gallery is much better at this.
And yep, that's all. They really aren't that much more useful than the ViewAnimator. Why Android development makes anything is really a mystery to me.
I would normally just prefer using a ViewAnimator because it gives you more freedom and thus flexibility in how you design. But if you want features like the ViewFactory and you only got 2 views use the ViewSwitcher. If you want to be able to periodically change views use ViewFlipper. If you don't need either use a ViewAnimator.
ViewFlipper supports more than two views, ViewSwitcher only supports 2.
I'm not sure if there's any big differences between them but from what I've gathered the difference is that ViewSwitcher is used in circumstances where the view is the same but the data is different - like on a calendar app - we're just changing the data in the view.
ViewFlipper is allowed in app widgets, while ViewSwitcher is not.
https://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout