How to animate ImageView in Android Widget most efficiently? - android

I'm trying to make animated widget for Android. I'm using Android Studio currently. It's a ImageView that rotates 30 times a second (30fps). I want to be able to change the rotating speed of the image. It's just like a clock (but turning much faster). I know, that this will pull battery energy extremely, but I think this is the only way to make it look like a "smooth" animated widget. Correct me if I'm wrong.
What is the most efficient way (for battery) to make something like this? I thought about following things like:
- Rotating ImageView 30 times a second with a Timer in JAVA (best way?)
- Trying to use a animated GIF (didn't got anything working yet - couldn't change the rotating speed that easy)
Any ideas?

Related

Faster scrolling background

I am developing a (vertical) scrolling shooter app for android. Everything is working fine, its fast and smooth... but so far it just has a black background. I wanted to make a scrolling background by creating a very tall bitmap of the background, and show a part of it using code like this:
canvas.drawBitmap(background_bitmap, sample_rect, fullscreen_rect, null);
where the sample_rect gets moved along as the game progresses. The code works, but the frame rate has now plummeted and is no longer smooth.
I can think of some possible ways to do this better, but it seems silly to reinvent the wheel if there is a standard method that everyone uses. Any suggestions?
EDIT: By the way the image is not a simple pattern that I can implement with small tiles.
EDIT: Should I be employing BitmapShader? Should I resize my bitmap to match the screen before the game starts?

Issues designing Android UI in Xamarin

I am in the process of writing my first android app. I figured, for a simple exercise, I'd write an app to keep score in bowling.
I want to create a picture of the pins, with a touch toggling a pin between standing, and fallen. Then an ok button, that completes the shot. After each shot is entered, have a picture of the score updated.
Then, I want to be able to click on a frame, and edit it...mistakes happen.
This seemed simple enough. At least if I were to whip up something in HTML5 I would be done by now.
However, I'm struggling with just drawing the UI...ugh.
Would I just create the pins as image buttons? And how do I align them properly...I can't seem to drag stuff where I want, it's all left aligned and stacked. Nothing like it should look.
And how can I dynamically create images for buttons? At least that's how I was thinking I would do the score (showing all 10 frames with the shots and running score.
I realize this is a beginner question. But I've been at it for five hours, and I'm no farther along.
I don't think it's necessarily fair to compare your speed in a dev environment you are new to with one you already know - you are bound to be slower in the new one.
To get more familiar with android's XML layouts, I recommend you take a look through some of the tutorials on layouts - on linearlayout, gridlayout, relativelayout, etc which I think will have you quickly working in XML to generate your ui.
One such tutorial is http://slodge.blogspot.co.uk/2013/01/an-mono-for-android-wrappanelflowlayout.html
Once you've learnt a bit about the XML, I suspect you'll also find the designer easier too.
For the questions about the pins, well these sound a lot like checkboxes, only drawn differently - so check out:
Custom checkbox image android
http://vimaltuts.com/android-tutorial-for-beginners/android-custom-checkbox

How to create a Raining Effect(Particles) on Android?

I am developing a 2d android strategy game, it runs on SurfaceView, so I can't(or can I?) use LibGdx's particle system. And I would like to make a raining effect, I am aiming for something like this( http://ridingwiththeriver.files.wordpress.com/2010/09/rain-fall-animation.gif ), I don't need the splash effect in the end (although that would be superb, but probably would take up a lot of system resources). How could I achieve that raining effect? Any ideas?
There's one similar code from JakeWharton called DroidFlake. It seem like snowfall effect but worthy to check DroidFlake
The easiest would be to put the rain drops in a PNG with alpha and display that at the end. You would only need a few frames to make it smooth, but it would eat up a bit of resources if this were a full screen image.
If you cannot afford this, you could put each distinct raindrop in a smaller PNG file with alpha, then display this (these) single PNG(s) multiple times. This would reduce the memory used a lot, although your rendering code will get a bit more complex, and depending on how many drops you have, it might affect performance.
A trade-off between the two would be to have a PNG file that contains more drops, but not for the full screen, and display that a few times.
You could have another frame (or frames) where the raindrop splashed, which you could display before ending the animation of each drop, or you could have the final frame in the large PNG contain the splashes.
There are many ways of doing this. You could create a sprite sheet like:
In that spritesheet, you could simply have a drop of water advance in each frame until it reaches the bottom and you create the splash effect. You then need to be able to animate it (very easy). You can then create multiple instances of the image, or draw the one image multiple times to create the rain storm.

Android - image transition velcome screen

I am creating turistic app and I have made some significant research about design. Now I want to try in Android display background image in main menu. Do you know, is it possible to have there image, which changes periodically with some transition effects? On background there should be turistic pictures, which will be changing time to time. Is it possible with Android? I am asking here, cos I wasn't able to find solution up to now.
Thanks
Did you tried to use this?
Why not! you can apply a thread which will change the background image from time to time, and if you are going to deploy it not ICS you can have the transition effect also.

Creating a 9 Patch with repeatining pattern

iam stuck with the creation of a nine patch for a progressbar background.
It has a repeating pattern like a ruler-scala and that given me headache.
here is a image of what i want(at the bottom) and what i have (top).
can someone give me a hint how to acomplish my goal?
edit: or is it generelly possible to do this with a 9patch?
my other attempt was to make a with android:tileMode="repeat" but there i get problems with the height of my image (repeating in the second line), i need something like repeat-x.
Thanks in advance
edit2: ok i managed to do my repeating 9patch by stretching the whole repeating pattern, but its not ideal :(
You seem to be overestimating the power of 9-patches. The most you could do is have a ruler image with expanding space between the ticks. You can't, however, make a 9-patch that automatically tiles parts of your image.
On the other hand, if you create a BitmapDrawable programatically, you can set the tile mode separately for the X and Y axes.
I used to do this in my webview project using border image which provides both options (repeat, stretch, fill).
As webview has kind of it's own problems in android (mostly fixed element) I decided to be more android for the next project and I found out that it's not possible to have the repeated border using 9Patch. It's so awkward as it's needy but not implemented.
In a word android development area makes me crazy, one option here one option there is a usual thing here.

Categories

Resources