标签:android stackoverflow surfaceview popupwindow
一、前言public void show( ){ if( null != mPopupWindow ){ mPopupWindow.showAtLocation(mView, Gravity.CENTER, 0, 0); } }
// 在界面组件onCreate函数中调用 final View anchor = findViewById(R.id.anchor); anchor.post(new Runnable(){ @Override public void run(){ // 构造和展现弹出窗口 PopupWindow window = createWindow(); window.showAsDropDown(anchor); } });
public void show( ){ mView.post( new Runnable( ) { @Override public void run() { if( null != mPopupWindow ){ mPopupWindow.showAtLocation(mView, Gravity.CENTER, 0, 0); } } }); }
四、题外话
今天想做一个在PopupWindow里面播放视频的功能,结果发现SurfaceView在PopupWindow中是无法正常显示的,如果需要显示SurfaceView,建议用View、Fragment或者Dialog Activity代替PopupWindow。我在StackOverflow上查了一下,说是SurfaceView必须要依附于window,但PopupWindow是依附于View的,所以Surfaceview在PopupWindow中无法正常创建,可参见:SurfaceView not working inside PopupWindow
在Activity的onCreate方法中显示PopupWindow导致异常的原因分析及解决方案
标签:android stackoverflow surfaceview popupwindow
原文地址:http://blog.csdn.net/ekeuy/article/details/42398009