后台服务形态

时间:2018-09-16 15:58:23

标签: java android service

enter image description here

我是android后台服务的新手...我设法在这样的服务中为xml布局添加

public class FloatingWindow extends Service{
WindowManager wm;
RelativeLayout ll;
LayoutInflater li;

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    final View myview;
    li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    wm = (WindowManager) getSystemService(WINDOW_SERVICE);


    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.TYPE_INPUT_METHOD |
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,// | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
            PixelFormat.TRANSLUCENT);

    /////////////////////////Another params


    params = new WindowManager.LayoutParams(
       750,1250,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);

    params.gravity = Gravity.CENTER | Gravity.CENTER;
    myview = li.inflate(R.layout.service_floating_window, null); // your layout here

    wm.addView(myview, params);
    params.x = 0;
    params.y = 0;

但是那只是膨胀一个xml布局...我可以获取有关如何制作具有不同形状的服务的代码,就像下面的图片...像一个半圆而不是常规活动shape(Rectangle)一样吗?知道我不应该这么快地跳到这么复杂的事情上,但是我只是想快速学习,并且看代码和理解是最好的方法...所以有人可以告诉我如何实现这一目标吗?

1 个答案:

答案 0 :(得分:0)

我想您的XML应该包含半圆形的视图,例如ImageView