PopupWindow其实类似于一个不能动的Widget(仅从显示效果来说!),它是浮在别的窗口之上的.。
import android.view.ViewGroup.LayoutParams;
handler = new Handler(){
public void handleMessage(Message msg){
switch(msg.what){
case 1:
Context mContext = Main.this;
LayoutInflater mLayoutInflater = (LayoutInflater) mContext
.getSystemService(LAYOUT_INFLATER_SERVICE);
View music_popunwindwow = mLayoutInflater.inflate(
R.layout.toast_item, null);
PopupWindow mPopupWindow = new PopupWindow(music_popunwindwow,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mPopupWindow.showAtLocation(findViewById(R.id.main), Gravity.CENTER, 0, 0);
break;
}
}
};
Timer timer = new Timer();
timer.schedule(new NewTimerTask(), 100);//渲染完毕后再使用,否则会抛出异常
public class NewTimerTask extends TimerTask{
public void run(){
Message msg = new Message();
msg.what = 1;
handler.sendMessage(msg);
}
}
参考来源:http://blog.csdn.net/android_tutor/article/details/5576533