0

I want to make my slider be always on top. - Already done. But I cant make him move. What changes should I do?

public class SliderOnTop extends Service {
    private SeekBar seekBar;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT);
        WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);

        RelativeLayout layout = new RelativeLayout(this);
        layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

        seekBar = new SeekBar(this);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 45);

        lp.bottomMargin = 0;
        lp.leftMargin = 0;

        layout.addView(seekBar, lp);

        wm.addView(layout, params);

    }

}
Joel Martinez
  • 44,051
  • 25
  • 123
  • 182
Mariusz
  • 1,625
  • 3
  • 20
  • 34

1 Answers1

1

You could probably listen to onTouch events on your View, and then change the margins accordingly.

Mark Gjøl
  • 1,769
  • 10
  • 20
  • Thanks a lot, this is the way i should probably go.. but I have a problem. Adding onTouchListener or overriding OnTouchListener of seekbar or maybe even the layout doesnt work. It doesnt capture my 'touches'. Im using http://stackoverflow.com/questions/4481226/creating-a-system-overlay-always-on-top-button-in-android as an example – Mariusz Jan 10 '12 at 15:20
  • You were right. I have added onTouchEvent to the added item and it works. Thanks a lot! – Mariusz Jan 11 '12 at 10:17