This is more of a question about animating than a specific problem coding. i need to fill in the broad strokes left by the research i've been doing.
What i'm trying to do:
The activity should load with only the a togglebutton visible. when the button is touched, a png will be animated to a certain position relative to the togglebutton. also, another button will slide in from off screen and slide off if/when the togglebutton is pressed again.
What i can't figure out:
I can draw an image, but only via xml. creating an imageview and setting the background programmatically does nothing.
When i draw from xml, i can't move the image when the togglebutton is pressed like i want to. when i call getPositionOnScreen() i get a null pointer, even though the complier can see i'm referring to the imageview described in both xml and in code.
I'm calling getPositionOnScreen because via xml, i have the image positioned behind the togglebutton so that it's not visible until the button has been pressed and the image starts moving. the idea is that with different screen sizes i won't know exactly where the view is until runtime. getPostionOnScreen allows me to get the coordinates of the imageview so i know where it has been positioned. when i have a start position, can tell it to "move up" on the screen from behind the togglebutton by simply adding to x or y until it's where i want.
This is the code to draw the image (inserted in the onCreate method).
This is the code i'm using to animate. when the button is clicked, it calls this method on the view from the listener.
I'm well aware that this is horribly wrong and won't work. what i need to understand is why.
I have tried a weather widget and its working fine. The Weather widget is an app widget and I update the widget once in 6 hrs similar to the application on android site using AlarmManager. Now I want to animate the widget (ImageView) every 100 ms similar to HTC homescreen.
I dont think AppWidgets will scale well for this case. How can I implement this widget?
I have seen "Custom Homescreens" in previous Android SDK's. Should I have modify the Homescreen widget for doing this or is there any other way.
I'm drawing a ProgressBar in a custom View (SurfaceView) to it's Canvas, and it's drawn as expected. Except that it's not animating, no matter what I do. My custom view is animated properly, but I cant change the progress of the ProgressBar.
I've created the ProgressBar like this:
And I draw it something like this (slightly simplified):
And I've tried updating it's progress manually as well:
Any ideas on what I need to do in order for my ProgressBar to animate or change it's progress.
I am using a SurfaceView, and wish to animate Drawables. All the animation tutorials I have seen concern using an ImageView, which as I understand is not a sensible approach from within a SurfaceView. Does anyone have any suggestions for doing frame-by-frame animation within a SurfaceView? Can it be done with openGL?
Is there a way of being notified when a TransitionDrawable has finished its transition? I'm looking for a way to animate the background of a LinearLayout, switching it back and forth between two images thus creating a pulsating effect. TransitionDrawable works nicely, but....once. I tried stacking several 'item' in the XML defining the transition, but no luck. It justs fades from item 1 to item 2 and sits there. I'm wondering if I shouldn't implement a custom Animation.
Does anyone knows if it's possible to animate different views during the same animation: I have a linear layout containing 6 dices (each dice extends a textview) and I need to animate each dice to simulate a roll (each dice will rotate on itself). I know how to do this rotation on each dice by using 6 animations, but I want to group these animations in one, so that I would be able to add an animation listener to execute further instructions at the end of this animation. I tried with an animationset but didn't manage to do it.
I'm trying to do something which seems simple. I want to have a map view, with a menu that slides up from the bottom of the screen where settings (for overlay) can be adjusted. However when I use a TranslateAnimation to affect the y position of the LinearLayout (which holds the menu), the buttons in the LinearLayout move, but there "hit area" stays in the same position as they were before the animation.
I've also looked into tweening the view's marginTop value, but haven't even been able to determine how that would be done.
I create a ProgressDialog in onCreateDialog() like so:
Android, in its wisdom (or serious lack of it) decides to cache every dialog created through onCreateDialog(). Because of that, any subsequent call to showDialog(DIALOG_PROGRESS_ID) results in the same ProgressDialog instance being used but the animation has stopped working.
I've tried to re-set indeterminate in onPrepareDialog(), but that doesn't do anything. There is likewise no obvious method to call on the dialog instance that will reset the animation.
But maybe there is a way to get the ProgressBar itself and start it animating? so I tried the following after I asked this question:
But it didn't work either!
So, does anyone know if there is a way to restart animation on a ProgressDialog? If not, is there a way that I can force every showDialog() call to call onCreateDialog()? (this second question was answered by @TuomasR, but after pondering it I don't think this is a very good solution to my problem)
Is there a way to animate drawables on a canvas using the android built-in animation classes?
Ive been modeling my test application, a game, after the example apps lunarlander and jetboy. They contain a lot of reusable code, but they manually update the drawable objects in real time. It seems like using the android animation built ins would be so much easier since they provide the type of animation I needŽa simple linear movement.
Is there a way to do this, or am I better off updating my canvas in real time much like the example apps.
If there is a way, could anyone get me started with some sample code? I am currently inheriting SurfaceView in my class.
I am using android.hardware.Camera to get a preview and display it on a custom SurfaceView that implements SurfaceHolder.Callback.
I am trying to zoom in to the camera preview surface by a specified scale (not using the camera's digital zoom) but I can't seem to find a correct way to do it. I also need to be able to zoom out and scale down the preview.
I was hoping to be able to do this using a ScaleAnimation but it doesn't seem to work on SurfaceView, nor the FrameLayout containing the SurfaceView.
I also tried setting the size of the SurfaceView using setLayoutParams but that doesn't seem to work too well on various hardware and it would be tough to animate smoothly.
How to achieve this effect? Right now I am starting to think I might have to implement this using GLSurfaceView but I'm very unsure.
I have an app that is working fine in 1.6 and up but crashing for apparently no reason in 1.5. The app suddenly quits with the following message...
This error happens when the app is 'idling' (ie not doing anything other than redrawing the screen). There is no state change and no user input. The error occurs after the same amount of elapsed time whatever I set the frame rate of the app to and occurs both on the emulator and device. Changing what I display on screen can stop the error but there appears to be no logic to this (in one instance not drawing a large image stops the error but elsewhere just drawing some text causes the app to crash in the same manner).
I am using SurfaceView for animations following the basic procedure in the Lunar Lander sample app.
I've tried Draw!, Draw(er), and MagicMarker, but I dunno, they each have their pros and cons and can't find one that suits me well. I'm not looking for Photoshop on my phone, but something better than a colored line. So what is your best drawing app?
I'm trying to learn about Android programming by rewriting a C app I've moved from DOS to X-windows to Windows as a learning tool. It's just a silly little app that draws symmetrical 'game of life' patterns on the screen in a kaleidoscopic fashion. It's structured so that the patterns do their own animations. I.e. there's a 'Life' class that produces the next generation and redraws itself from the center outward, inserting delays to produce a kaleidoscopic effect.
I've got it so that the patterns draw - I took the LunarLander sample as a starting point, and an drawing on a SurfaceView. But my problem is with timing the 'animations'. I'm not doing traditional animation, where I build a whole frame and then draw it, but the surface seems to want to draw itself completely on each iteration of my loop, so my inserted sleep's don't insert delay in the right places.
So my questions:
1. Is there a more direct way to write to the screen than via a SurfaceView? If I did that, would the various steps of my 'animation' occur as I drew them, producing the desired effect. 2. If such a drawing method exists, would I be wasting my time learning how to use it? 3. What's the 'standard' way to do this kind of animation?
I have to recommend just getting a book on the subject.I learned most everything off of examples and documents on the web.After several months, I finally picked up the blue book and everything I had scoured to find is clearly demonstrated in it.Look for the red book and the blue "superbible."They cover everything you need.There are also books specific to ES.Make sure to get a good 1.1 one and not a 2.0-only one.
From the JavaDoc, it said it returns 'a bitmap representing this view or null if cache is disabled'. My question is what if the View is longer than the phone screen (you need to scroll vertically), what does the bitmap return? * only the visible portion of the view * everything the view has (both visible + invisible part)
I'm trying to create on of these images, but Eclipse won't accept it once I've used the draw9patch tool. I've found other people having the same problem, and saw this comment: I discovered later that the problem I was having was caused by the image not being exactly true to the nine-patch spec as defined in the documentation. Once I fixed the image to have a clean (i.e., no gradients etc) one pixel border it was fine. "'m not much good when it comes to image design. What does this mean, how do I create my original png file to meet the specification for Nine Patch?
I am creating a custom view which has an image. The image can be of any type. What i want to achieve is that i want to draw an EditText control on top of the image so that the user can add some values to it. I am not sure how to achieve this. The onDraw control will not allow me to draw any view right? I am new to android so any help would be appreaciated.
I'm having a small problem with drawing a View offscreen to a Bitmap. The View is created using LayoutInflater.inflate(int resource, ViewGroup root) with null passed to the root parameter. The View has a fixed size (200x180 pixels). I can create a Bitmap for this View either by using the method View.getDrawingCache() or by calling View.draw(Canvas canvas) using a Canvas that in turn has a backing Bitmap. This works fine if the View doesn't change after the inflate. However, if I have a TextView inside my View that I will update, the size of the TextView is never updated regardless of what method I call on the View (requestLayout(), forceLayout() invalidate() etc.). If I display the View on screen directly, everything works fine (sizes are updated as needed, etc.). What is the correct way of drawing Views off screen and being able to update their layout when needed?
I'm trying to create a custom widget which looks lick HTML table. I chose to derive from TableLayout, which is the subclass of ViewGroup and View. What's confusing me is that the drawing I put into my override of View.onDraw did not take effect, until I moved the codes to the override of ViewGroup.dispatchDraw. I know dispatchDraw is a good place to draw something, but I'm just wondering why there's such difference in my practice?
I'm trying to build a custom clock view in Android. See image http://twitpic.com/1devk7.So far to draw the time and hour markers I have been using the Canvas.rotate method to get the desired effect. However, notice that it is difficult to interpret the numbers in the lower half of the clock (e.g. 6 or 9?) because of the angle in which they are drawn.When using drawText, is it possible to draw the text at 45/90/180 degrees so that all text appears upright when my onDraw method has finished?
I wrote a reading software. I implemented the page turning effect when user tap the screen to turn to next/pre page. The display is ok on G1 (320X200 size) but it can not works well on Droid(480*854 size), the font looks a litter fuzzy, not clear as G1. I explain my codes for page turning:
1) create a canvas A
2) create bitmap.
3) set bitmap on canvas A
4) draw the new page content on canvas A
5) the current showing page has been saved in bitmap before since we do from step 1) to setp 4),
6) In order to implement the turning effect of scrolling from left to right, I draw the old bitmap part and draw the new bitmap part until the whole new bitmap has been drawn. all of bitmaps are drawing by canvas.drawBitmap() in onDraw() function.
7) when step 6) is done, it means the new page has been shown on screen, and the bitmap has been saved to use in next page turning.
The above is the whole actions for my page turning. On G1, no problem. But on Droid phone, the font is not clear, I tried if I directly draw text by canvas in OnDraw() not through bitmap, It is ok, but it can not implement the page turning effect that I need. I don't know why, could you please help me to take a look and tell me where is wrong or miss some steps?
When I try extending the View class to a subclass that will underline portions of the text drawn by ListView, the code compiles okay but results in a runtime exception apparently due to an improper class cast. Does anyone see what I've done wrong or have suggestions about getting access to the Canvas of ListView items so portions of text can be underlined?
Here is the code, which is the Efficient Adapter View/List example from ApiDemos with an added UnderlinedView class.