0
我想讓滑塊始終位於頂部。 - 已經完成了。 但我不能讓他搬家。我應該做什麼改變?滑塊始終位於頂部 - 無法移動
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);
}
}
非常感謝,這是我應該去的方式..但我有一個問題。添加onTouchListener或重寫seekbar的OnTouchListener或甚至佈局不起作用。它並沒有捕捉到我的'觸動'。我使用http://stackoverflow.com/questions/4481226/creating-a-system-overlay-always-on-top-button-in-android作爲例子 – Mariusz 2012-01-10 15:20:51
你是對的。我已添加onTouchEvent到添加的項目,它的工作原理。非常感謝! – Mariusz 2012-01-11 10:17:25