I want to animate an ImageView inside a WindowManager. But it is not working. Please find my code below. Here you can see I get a window manager system service and added an imageview. Now I am trying to rotate after adding the imageview inside window manager.
It works fine inside an activity.
public class FloatingImageAnimationService extends Service {
private WindowManager windowManager;
private static ImageView chatHead;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
chatHead = new ImageView(this);
chatHead.setImageResource(R.drawable.image_small);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = 0;
params.y = 100;
windowManager.addView(chatHead, params);
RotateAnimation ra = new RotateAnimation(
0,
-80,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF,
0.5f);
// how long the animation will take place
ra.setDuration(210);
// set the animation after the end of the reservation status
ra.setFillAfter(true);
// Start the animation
chatHead.startAnimation(ra);
}
}
Please let me know what additional steps I need to do to make it work.
Thanks you,
Bikash