Android: swapping two elements on swipe, like Candy Crush - android

I am developing my first Android game whose main screen is composed of a 4x4 array of views, each view contains an image and a text. When we touch on a view and swipe it to the position of a neighbor view, the two views are swapped, just like Candy Crush. I've been searching for a couple of days but I haven't found any appropriate solution. I concern about the following problems:
Should I use GridView or simply an array of views for such swapping?
What kinds of event should I process for this requirement?
How can I add animation so that two exchanged elements seem to have a real moving effect.
Any help would be much appreciated!

This Link should point you in the right direction. Note this will also work with GridViews. You just have to add your desired rules for filtering which items may/may not be swapped with eachother.

Related

Recyclerview adapter/layout that supports a matrix, or multi-dimensional data

I've used Recyclerviews with one dimensional data (lists) but that's one dimensional and not what I need. The Grid layout doesn't appear to be quite what I'm looking for as it's used to display a list in a grid like fashion. But the data I'm looking to display is lists that contain lists that contain lists. Essentially, what I want it to look and feel is similar to how Trello does it, however, I'd like all the lanes to move vertically and horizontally in unison, and the lane headers to be fixed at the top at all times. Additionally I'd like groups within the lanes and of course, drag & drop. There's really nothing quite like it out there from what I've seen and almost makes me wonder if the Recyclerview is really even capable of something like that.
My question is, what would be a good approach for something like that? One idea is to not use a Recyclerview at all and just render all the data into a giant scroll view and have the user pan around, but the load time and memory foot print would be kinda horrible (we could have hundreds of items to display). That's the approach we took on a UWP app we made and the results weren't pretty.
Another idea is to make an outer Recyclerview scroll horizontally and each "item" would contain a Recyclerview that scrolls vertically. We'd then need to find a way to scroll all the Recyclerviews vertically when anyone one of them is scrolled, and from what I can tell that's a non-trivial task but it might not be impossible. And we may be able to live with them not scrolling in unison, not sure.
I'm also toying with the idea of making my own layout manager and adapter combo. Not sure if that's all I need or if I also need to extend the Recyclerview. That seems like the most complex approach but it might be the best option in terms of quality.
EDIT: Currently looking into the FixGridLayout from the Recyclerview-Playground project on Github. That has the two-way scrolling but it's still one dimensional data. Getting closer.
Any other ideas?

List with views stacked on top of each other

You usually traverse a list by scrolling through the views that are placed one after another. What I'm trying to achieve is similar, but the views would be stacked on top of each other. The views will also cover the whole screen. So when you scroll, the top view slides away (or uses some other transition animation), but the bottom one is not moving underneath. You can imagine that the views are like the papers in a top spiral-bound notebook.
So my question is - does something similar already exist? I haven't been able to found anything so I might need to make a custom implementation. Oh and the views will each contain an image and there might be quite a few of them, so it will need to handle that (I was thinking of using Android Universal Image Loader). Thanks.
Sounds like you want to use Depth page transformer, via http://developer.android.com/training/animation/screen-slide.html#pagetransformer

Android ListView for showing lyrics

I am trying to make a ListView for showing lyrics. I have very little experience with making custom compound views. So I would like to know what my approach should be to make this view. The ListView must have these features
auto-scrolling based on the song (the timing information will be stored in the list adapter)
highlighting the current line which is being played on the audio
indentation on some lines to make it look more like a nicely formatted poem
users should not be able to scroll the list when the song is playing (i.e. the list is being auto-scrolled) but it should be scrollable when the song is paused
I don't know if the view should extend list view or not. If not then what should it extend and what should be my approach?
Frankly, I really don't have enough information to answer this completely, but this is what I would do:
If it were up to me, since you don't want a scroll capability at all (you want to make it appear as if it is scrolling, not to actually allow the user to scroll), I would not use any of the complex views like ListView or ScrollView, I would just write a custom view, simply extending View. I would override it's onDraw() method and use Canvas.drawText(...) to draw the words, having two different Paints, one for the current word and another for all other words. As for the "scrolling" effect, you can keep a number that represents the current top line that you can see, and add one to this number when you want to scroll to the next line. However to make it smooth you can manipulate where exactly you start drawing the texts and move it slowly upwards, so that it would appear that everything is scrolling down.
** Maybe it would be better to use SurfaceView here instead of just View, especially if you want a background image and smooth blending and better a look, since SurfaceView is much better for complex drawings **
If that is too complicated for you and you want to use existing views entirely without doing any of the drawing yourself, I would recommend a vertical ScrollView, you fill the ScrollView with horizontal LinearLayouts for each line, and each of those is filled with TextViews for every specific word. You can programatically build the TextViews and the LinearLayouts. Use ScrollView's scrollTo(...) or SmoothScrollTo(...) to scroll to the right location. You can prevent the user from scrolling by capturing all the motion events before they are used to scroll.
Both approaches will of course require you to maintain some form of data structure to hold the times each word is selected.

What's the difference between HorizontalScrollView & ViewPager?

I'm new programming in Android and i have many doubts about what type of classes can i use in my first app.
I want to do a level menu like cut the rope or angry birds. Only a title and a slider menu.
I think that can do with the two classes, but I'm not sure which is better, can you tell me the difference and which is better to use?
Many thanks.
ViewPager allows you to flip between pages of data (between views). You supply an adapter to generate the pages that the view shows.
But HorizontalScrollView is a container for other views that you can scrolled through, allowing it to be larger than the physical display.
I would go with horizontal scroll view.
EDIT : See FoamyGuy's answer in Angry Birds like scrolling menu where he exactly explains how to achieve such effect.

Android TableLayout vs GridView vs Other?

I am developing an app and am looking for some general guidance:
The app is a memory trainer, and will have a couple of different modes:
Numbers: Up to 400 digits will be displayed on the screen in a gridlike pattern
Faces: Images of faces will appear, approximately 9 to a page, also in a grid pattern
The question is: can I accomplish this with a single xml layout file, and should I use the same layout type for each (and if so, what should it be!) ? It's a large app, so consistency would be heavenly.
I would prefer a layout with flexibility, and I am leaning toward GridView right now.
Any thoughts?
A Grid view is basically like a list view where items are arranged in a static grid.
It retrieves views from the Adapters as scrolled by user.
A table layout is a layout manager and does not do scrolling if required.this means u have to put it inside a scroll view. This implies that all of the data you are displaying must be populated into the TableLayout up-front, so the ScrollView knows the total space it is to scroll in. It also does not directly give you per-"item" selection or interaction, because a TableLayout doesn't have items, it is just a layout manager.
Also Adapter -based view should be used where significant amount of data is there to be scrolled. So it seems that grid view would be more suitable in the situation u r working.

Categories

Resources