I want to implement a graph as below for each item of a listview.
The cell will turn green or red based upon the input.
The number of coloured cells will increase based upon the input.
Could you please tell me what would be the best approach in attaining the same. Right now I have used table view to achieve this. But the list view is very slow. Tried searching for some third party graph libraries but had no luck.
Thank You.
If there's a fixed number of cells, you could define a custom view.
Inside the custom view, you can then define a canvas, where you can draw colored rectangles. Just provide some kind of update method for your custom view, to keep the canvas refreshing whenever there's a data change.
The advantage of this solution:
+ It's faster than hiding / showing and inflating views
+ You can custimze it much faster
+ You have all functions you need in one class
And it's relatively easy to accomplish, have a look at the android developer page for this topic: https://developer.android.com/training/custom-views/index.html
Related
I have a specific goal regarding animation using Recyclerview, but I cant find an exact title to convey my concern, so I'm open to any correction if necessary. So first , I have a recyclerview that acts as a ViewPager thanks to David Medenjak's Recyclerview ViewPager
Now I have a requirement to animate the background color for each swipe transition, thanks to different links and resources, I stumbled upon TransitionDrawables, putting an array of different drawables and invoking a necessary transition functions to animate,
recyclerView.setBackground(arrayOfDrawables)
transitionArrayOfDrawables.startTransition(...);
Now I want to take things deeper, I want to manually control the transition relative to the animation of the swipe of each item of the recyclerview, Im mentally blocked as I cant find the keyword to search for where should I start, "Interpolation", "Manually interpolating a views animation", things like that, but still no luck, the only thing that I have on my mind is "Get the recyclerview's visible item's interpolation/animation-value then supply it to the target view's animation manually", but I dont know where to start, I dont even know how to animate view's manually, I have experience with ObjectAnimators, simple translating, scaling, bouncing etc.. but controlling view's animation manually and relatively even by using knob/seek bar or such, its just out of my domain as of the moment.
Any help would be greatly appreciated.
[Edit] Apologies if my question's intent covers alot of demands :(
If I am understanding correctly, this link may be of some use. It provides instruction for how to gradually transition between viewpager background colors in relation to the user swipe.
The example uses the ArgbEvaluator class which -according to the doc: "...perform[s] type interpolation between integer values that represent ARGB colors."
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.
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.
I'm creating a Kakuro game for Android and it mainly consists of a large grid which contains only black and white squares according to a pattern. I have decided to use a custom class extended from Button to represent black and white squares.
But the problem is, I can't figure out what to use and/or extend to represent the square-containing (Button-containing) grid. It should have the following behavior:
Should be able to house Buttons along both x- and y-axes.
Should be scrollable in both ways as the grid will most definitely exceed the device's screen size.
Should not be too hard on the memory footprint.
So after some thinking, I have decided to create a custom class that extends View. But I don't know exactly which methods to override to obtain the behavior I want.
So can anyone please tell me which methods I should override to obtain the behavior I need? (The behavior is somewhat similar to that of Minesweeper).
Or is there any other easier/faster method I can use?
Thanks in advance!
if it is a grid you want, I recommend the GridView.
A view that shows items in two-dimensional scrolling grid. The items
in the grid come from the ListAdapter associated with this view.
GridView tutorial: http://developer.android.com/resources/tutorials/views/hello-gridview.html
Extending the GridView seems more suitable for your need: http://developer.android.com/resources/tutorials/views/hello-gridview.html
I was wondering if there is a way that I can animate my GridView's Children to their new positions. So, for example, slide in from the left and when at the end of a row, slide off to the right. This will give the effect of each child moving to its new position, rather than just appearing there.
I have looked around, and could not find any useful information. Ideally a small code sample will get me on my way.
Thanks
You should consider using GridLayoutAnimationController. GridLayoutAnimationController docs
You may try looking at this video:
http://www.youtube.com/watch?v=X984r7IOrgc
The developer somehow shares how he had implemented the animation in his reply on one of the comments. He could not show the source code yet though. Hope this helps.
i used android canvas and some code for positioning image tiles. it
uses and data adapter pattern (like for all AdapterViews). each tile
has it's position - page, row and column. draging changes tiles
positions. - karooolek
There are a few animations in the Android API Demo, including some animations for gridview.
You might want to check the examples in com.example.android.apis.view.