Not sure how to do this, or what the right terms are for describing this, but here goes:
I want to make a closing circle animation in my android app, much like the end of this video. I'm guessing what I need to do is somehow draw a black circle but instead of filling the inside of the circle fill the outside. How exactly would I do that, given the tools I have with Android's Canvas class?
Have you tried using clipPath to achieve this?
I was working on the same kind of thing and achieved it by using clipPath of canvas.
Related
I am trying to draw something like this http://www.laviny.sk/themes/hzs/images/pocasie/r/r2.png using android XML shape. It is one big triangle (45° on bottom) and one smaller triangle on top of it. I am planing on using it on image like this http://www.laviny.sk/themes/hzs/images/pocasie/r/r0.png. I know that I could use simple png image of this but I want to set its color programatically so thats why I am trying to use android shape.
Is this too complex to be drawn by shape? If not can you please try to guide me a bit because I really dont know how should I approach this problem.
Thanks in forward
Layer-list should be able to do that. The other way is to extend ImageView and draw what you like on a canvas within the onDraw method.
on a canvas is it possible to draw text but make half of it not show up (as if it is being drawn partially off of the canvas, but actually not being off the canvas). i have an indicator on a "graph" with some text and it follows the point but I do not want the text to be drawn out of the graph portion (i am drawing other stuff outside that area).
I also have a background on the layout behind the canvas so I cannot just paint with a bitmap because that would cause some aspect ratio/sizing issues (wouldn't look good).
I have tried looking for answers all over Google, Stack overflow, and by experimentation with no avail. On Google I found many interesting things about drawing text on an android canvas but nothing that I was looking fore, I am pretty stumped, and I am starting to think that what I want is not even possible, and i may need to draw the text custom with points or figure out an alternative that looks just as good.
It's absolutely possible. Probably the fastest is to use clipRect to limit drawing to your graph portion. See this answer: Using clipRect - explanation
The reference on the various forms of clipRect is here: http://developer.android.com/reference/android/graphics/Canvas.html#clipRect(android.graphics.Rect, android.graphics.Region.Op)
If I recall, the whole operation will look something like:
yourCanves.save()
yourCanvas.clipRect(...)
yourCanvas.drawText(...)
yourCanvas.restore()
The restore() call serves to undo the clipRect so you can draw outside it for later drawing.
The simplest solution that popped in my mind, would be to cut using substring the text that you want to dispaly.
Example:
if(MyString >5){
canvas.drawText("VeryLongTe...");
}
I'm trying to create an interactive accordian/concertina/folding animation so that a view folds/unfolds on itself when interacted with - in the same way flipboard folds the view, but both sides fold
The way I thought I could do it was to override the onDraw method, somehow duplicate the canvas or the information on the canvas, then draw the first half of the canvas rotated one way, then draw the other half of the canvas rotated the other way so that they meet in the middle, however I can't seem to grab the information from the canvas! Is it possible to grab a bitmap/snapshot from a canvas?
The only other way I think it's possible to achieve this kind of animation is with OpenGL.
Any help are greatly appreciated.
EDIT heres a good example of what i want to achieve http://www.nytimes.com/interactive/2008/03/28/arts/20080330_FOLD_IN_FEATURE.html
check this archive to acheive fold animation
code: http://developer.android.com/shareables/devbytes/FoldingLayout.zip
modifies it to make it work for lower version up till API level11
I've got some problem. I have an image drawn using canvas, and I would like to animate it. I would like to do something like TranslateAnimation, but TranslateAnimation works only with views, and my image is not a view. What can I do?
Personally I haven't worked with Android canvas, but I am fairly certain that what you need to do is this:
Draw your shape on the canvas
Wait for a couple of miliseconds
Clear the canvas
Redraw shape to next immediate position
and repeat this until the final position is reached.
From my little knowledge the canvas is more similar to a piece of paper than to a flash animation. You need to draw, clear, recalculate, redraw. I highly recommend reading some more on the topic. Firstly, I would start with the android canvas reference: http://developer.android.com/reference/android/graphics/Canvas.html
and then try some tutorials like canvas frame by frame tutorial for android : http://developingthedream.blogspot.ro/2011/01/android-canvas-frame-by-frame-animation.html
And also I highly recommend looking up things on google first before posting a question on stack. There is a good chance, especially if you are a beginner, to find existing tutorials with everything you need and more. Good luck learning.
I have a background image that I would like to simply scroll (while looping) right to left. What is the best way to go about doing this? Will I need to use an external library? Are there certain methods built into android already to accomplish this? Is all this accomplished in the doDraw() method?
Eventually I would like the canvas to also draw a stationary Bitmap ontop of that. I think that will be easy if I just use the canvas.drawBitmap() function.
Easy example including X offset
http://android10.org/index.php/articlesuserinterface/256-live-wallpaper-example
and canvas