0
我已经按照以下教程介绍了如何使用窗口管理器在所有其他窗口之上添加简单视图(在教程中是其图像)。如何使用窗口管理器将LinearLayout作为system_alert添加
http://www.piwai.info/chatheads-basics/
它的工作原理是,当我试图与ImageView的使用它的魅力。当我尝试使用ViewGroup子类(如线性布局)进行操作时,没有显示任何内容,我不知道为什么。
这里是我的代码
package com.example.servicedialogexample;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class HelloService extends IntentService {
private WindowManager windowManager;
private LinearLayout m_viwAlert;
private ImageView im;
public HelloService()
{
super("HelloService");
m_viwAlert = null;
windowManager = null;
}
@Override
public void onCreate() {
super.onCreate();
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
m_viwAlert = new LinearLayout(this);
im = new ImageView(this);
im.setImageResource(R.drawable.ic_launcher);
WindowManager.LayoutParams params1 = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params1.gravity = Gravity.TOP | Gravity.LEFT;
((LinearLayout)m_viwAlert).addView(im, params1);
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(m_viwAlert, params);
}
@Override
public void onDestroy() {
super.onDestroy();
if (m_viwAlert != null)
{
windowManager.removeView(m_viwAlert);
}
}
}
我不知道我在做什么错误在这里...提前
感谢这里帮助我:)