I wish to draw endless board like game world map of endless cell grid. User will be able to scroll it, but the data will be stored in memory, not on scree. I.e. I will populate cells when they are appear on screen and delete them on hide.
How to implement this in Android?
In javascript and java I would use 2 nested absolute panes or divs with no clipping.
You can do the same thing with a RelativeLayout by changing the view's left and top margin as if it was the x and y coordinate.
The best way is to override onDraw(Canvas canvas) method of View sub-class and paint the area you want to display. Put your game character in the center and redraw the View with invalidate().
Related
I need to draw a reverse Z shaped figure like this in Android using View element. I can't use any image. I need to achieve it using View.
Explanaton of the attached image :
The rectangle box represents the screen of the mobile device.
The reverse Z shaped figure is what I need to draw using View; such that the center of the slanting line ("/") should coincide with the center of the device screen. The other two lines should be of same length as well.
The figure should be relative to the screen sizes.
Thanks!
Create a custom View (a class that extends View)
Call setWillNotDraw(false) in its constructor (to make sure your custom onDraw will be called)
Create custom onLayout method in which you will calculate positions of those four points (store them as fields of your custom View):
Create custom onDraw method in which you will use various Canvas methods to draw your things.
Frame: use drawRect with Paint object that has stroke
"The reverse Z shaped": there many ways to draw this thing e.g. use drawLines to draw lines between points calculated in 3.
I have extended ListView such that I can have a fast scroller. In the onDraw method I draw a rectangle with lettering along the right edge of the list, and if you are actively sliding your finger up and down I render the current letter in the center of the view. The problem is the list items render on top. Not idea.
I am looking for the best way to render my background, then my list items, then my foreground.
Override dispatchDraw() instead of onDraw(), and draw your fast scroller after calling through to the super method.
I want to create the following view / set of views which behave following way:
I have huge set of points which have been stored to DB in web server.
My client application downloads those and should draw curved lines about the data.
What components should I use here to get this "infinite" scrolling view to draw content dynamically.
No snapping wanted, so it should be smooth and can stop to every X position.
Should I proceed with this by using HorizontalScrollView with horizontal LinearLayout and remove/add views based on scrolling, then translate the scrolling position and provide fling that the scrolling doesn't stop suddenly.
Or is just one canvas possible to use and draw the content to simulate the scrolling?
Maybe a horizontally scrolling ListView component?
The solution should be efficient and use minimum of memory.
Which solution do you recommend, or do you have some new ideas other than above?
All suggestions are highly appreciated. Thanks.
There is several possibilities:
Create custom View class and implement GestureDetector there. You can get movement of finger, calculate currently visible area and draw only visible part of content.
May be this solution is not the easiest to implement, but it will be fast and does not require any resources.
I'm currently trying to create a circle (via canvas drawing, opengl or drawable) and define 4-5 buttons inside of it. My first thought was to create some drawables (quarters of circles) and overlay them onto the main circle, but then I'll have the touchable zone too large - e.g. in the middle of the main circle.
Is there anyone who tried this and found a decent solution to it?
You could just override onTouch() in your custom View that draws the circle (and other button graphics), and do a bit of simple maths when you get the finger down event to determine whether the user has touched within the circle, and what particular defined zone within the circle.
How to use Customized fonts on Canvas?
I have customized view (PIECHART DRAWN ON CANVAS) on left side of the screen and list view on right of the screen. When ever I touched on the canvas list view values has to be changed. is it possible. My listview is in Activity A class.And view is in B class.
I have piechart with n no of arcs. On tapping on that i have to known which arc is tapped. Is there any formula for it. (Like for rectangle basing on left,top and width hegiht we can check.)
In the drawText function in the canvas you have to provide a Paint object. Well the paint object has a function that accepts a typeface and it is called setTypeface(). Look more into that function and its uses and perhaps this tutorial and you will see that it is rather straightforward to use any font that you like in Canvas.
My advice would be to make questions 2 and 3 separate questions in their own right and improve your explanation of what you want to happen.