Reputation: 3600
I want to show current location of user on Google map. Every thing is working fine for me . I am just using marker to show current Location on map. Now I want to make that marker to be blink as in original google maps app on android mobile. I think I have to use animation for this purpose,But I dont know how to use it. I am searching it in internet but I am not getting any solutions . Anyone help me please.....
Upvotes: 7
Views: 8163
Reputation:
Since the marker itself is not a view it seems using the animate framework is not a possibility.
So, the following approach (albeit rough around the edges) works although in the interest keeping it on point: - it does not stop (just add a flag to check set somewhere else) - you'll want to cancel it on next marker click to avoid running multiple times on same marker
Assume you have a reference to a Marker (e.g. use the onMarkerClick callback) and you are executing on the UI thread. Use the markers alpha setting and step it down or up (at 0.1 steps in this example) from 1.0 to a lower limit (0.5 in this example)
// Assume I have a marker reference 'm', e.g. from a onMarkerClick
// .. in context of onMarkerClick for example
// change the '500' (millis) to adjust the blinking rate.
new Handler().postDelayed(new AnimateMarker(m, 0.5F, 0.1F), 500);
... and elsewhere in class define
public class AnimateMarker implements Runnable {
float tgtalpha;
float delta;
private Marker m;
public AnimateMarker (Marker m, float tgt, float delta) {
this.m = m;
this.tgtalpha = tgt;
this.delta = delta;
}
@Override
public void run() {
float a = m.getAlpha();
if (a <= tgtalpha || a >= 1.0F) {
delta *= -1.0F;
}
a += delta;
m.setAlpha(a);
new Handler().postDelayed(new AnimateMarker(m, tgtalpha, delta), 500);
}
}
Note you can do different things in the run() such as "spin" the marker by using the rotation property:
// modified snippet of 'run' method
float a = m.getRotation();
if (a >= 350.0) {
a = 0;
} else {
a += 10.0F;
}
m.setRotation(a);
Other possible properties to manipulate (or combinations): - anchor point - this will cause it to wiggle if done smartly - visibility - make it appear/disappear (probably annoying)
Upvotes: 0
Reputation: 5785
Android GPS icon on the status bar blinks using the below logic. Keep two drawables one with dull image and one with bright image. Change them at certain duration and it will look like the image is blinking.
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/dull" android:duration="10000" />
<item android:drawable="@drawable/bright" android:duration="10000" />
</animation-list>
Upvotes: 6
Reputation: 45942
this is exactly what you need
http://www.wiseandroid.com/post/2010/08/10/Making-a-simple-custom-Android-UI-animation.aspx
I hope you understand the code. notice this statement:
t.setAlpha(Math.abs(FloatMath.cos(period)));
I think you must edit it to make it change from 1 to 0 then from 0 to 1... etc
Upvotes: 0