可能会膨胀服务中的XML布局? (机器人)

我想在服务中夸大一个xml布局.你怎么做到这一点?我试图使用inflater和Window Manager,但我认为它不起作用.有什么策略吗?谢谢.
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/main"
>
    <LinearLayout
        android:id="@+id/top"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        >


    <FrameLayout
        android:id="@+id/topLeft"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        android:tag="topLeft"
        android:layout_weight="1.0"
        android:background="#ff3d38"></FrameLayout>


    <FrameLayout
        android:id="@+id/topRight"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:tag="topRight"

    android:layout_weight="1.0"
        android:background="#fff839"></FrameLayout>

    </LinearLayout>

<LinearLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal"
    android:id="@+id/bottom"
    >

<FrameLayout
        android:id="@+id/bottomLeft"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        android:layout_weight="1.0"
        android:background="#1e22ff">

    </FrameLayout>

    <FrameLayout
        android:id="@+id/bottomright"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        android:layout_weight="1.0"
        android:background="#32ff1f"></FrameLayout>

这是我的服务代码,用于显示xml.

package com.toksis.pvscreen;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;


public class DragDropButtonMainService extends Service {
private LinearLayout main;
private LinearLayout firstLayer;
private LinearLayout secondLayer;
private FrameLayout  vTopLeft;
private FrameLayout  vTopRight;
private FrameLayout  vBottomLeft;
private FrameLayout  vBottomright;



private Button mainButton;
private ViewGroup mView;
private LayoutInflater inflater;

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


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

    createDragDropLayout();



}



void createDragDropLayout(){

   mainButton = new Button(this);
   mainButton.setText("Main");


   WindowManager.LayoutParams params = new WindowManager.LayoutParams(
           WindowManager.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.TYPE_PHONE,WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                   | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                   | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,PixelFormat.TRANSLUCENT
   );




   WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);

   inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

   mView =  (ViewGroup) inflater.inflate(R.layout.dragdroplayout,null);


   vTopLeft   = (FrameLayout) mView.findViewById(R.id.topLeft);
   vTopRight  = (FrameLayout)  mView.findViewById(R.id.topRight);
   vBottomLeft = (FrameLayout) mView.findViewById(R.id.bottomLeft);
   vBottomright= (FrameLayout) mView.findViewById(R.id.bottomright);
   firstLayer = (LinearLayout) mView.findViewById(R.id.top);
   secondLayer = (LinearLayout) mView.findViewById(R.id.bottom);

   //    main = (LinearLayout) mView.findViewById(R.id.main);

  //        main.addView(firstLayer);
  //      main.addView(secondLayer);


 //    firstLayer.addView(vTopLeft);
 //           firstLayer.addView(vTopRight);

 //         secondLayer.addView(vBottomLeft);
//       secondLayer.addView(vBottomright);

  // wm.addView(mainButton,params);
     wm.addView(mView,params);

   Log.d("tok","add mview");


   }
}
可以在服务上放置图形,代码是:
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);

        params.gravity = Gravity.RIGHT | Gravity.TOP;
        myview = li.inflate(R.layout.traslucent,null);     

        wm.addView(myview,params);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇