Android 安卓PopUpWindow
我有一个应用程序,它有一个创建曲面视图的活动,在曲面视图中放置一个OpenGL渲染器。我在OpenGL渲染器中处理对象拾取。我想做的是当用户选择一个特定的对象时,显示一个文本块和一个我存储在文件中的图像。Android的PopupWindow类似乎可以很好地完成这一任务。我能在OpenGL渲染器上覆盖弹出窗口吗?还是我在倒退Android 安卓PopUpWindow,android,opengl-es-2.0,popupwindow,Android,Opengl Es 2.0,Popupwindow,我有一个应用程序,它有一个创建曲面视图的活动,在曲面视图中放置一个OpenGL渲染器。我在OpenGL渲染器中处理对象拾取。我想做的是当用户选择一个特定的对象时,显示一个文本块和一个我存储在文件中的图像。Android的PopupWindow类似乎可以很好地完成这一任务。我能在OpenGL渲染器上覆盖弹出窗口吗?还是我在倒退 谢谢好吧,我的朋友,我和你有同样的问题。我将解释我做了什么,我认为这符合你的问题 我有一个显示网格的渲染器。用户可以在网格上放置注释。我也像你一样做光线拾取。当用户单击注释
谢谢好吧,我的朋友,我和你有同样的问题。我将解释我做了什么,我认为这符合你的问题 我有一个显示网格的渲染器。用户可以在网格上放置注释。我也像你一样做光线拾取。当用户单击注释时,将显示一个弹出窗口 本质上,您需要做的是在渲染器中调用一个方法,该方法将在UI线程中运行弹出窗口。(OpenGl在自己的线程上运行) 更具体地说,您必须向将显示弹出窗口的处理程序发送消息 YourRenderer.java
@Override
public void onDrawFrame(GL10 gl) {
.... code that displays the mesh ...
if(userRequestedPopup) {
Message message = new Message();
message.what = DialogHandler.OPEN_ANNOTATION;
// Here you can create a Bundle in order to pass more data inside the Message
dialogHanlder.sendMessage(message);
userRequestedPopup = false;
}
....
}
public Popup(Context context, Message message) {
this.context = context;
Activity parent = (Activity) context;
// here you can have the instance of the holder from glSurfaceView
LinearLayout parentLayout = (LinearLayout) parent.findViewById(R.id.popupHolder);
// inflate your custom popup layout or create it dynamically
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.popup_layout, null);
// Now you should create a PopupWindow
PopupWindow popupWindow = new PopupWindow(view,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
// you can change the offset values or the Gravity. This will diaply the popup in the center
// of your glSurfaceView
popupWindow.showAtLocation(parentLayout, Gravity.CENTER, 0, 0);
}
YourGLSurfaceView.java您应该在这里创建处理程序
public class DialogHandler extends Handler {
... other constants ...
public static final int OPEN_ANNOTATION = 2;
...
@Override
public void handleMessage(Message msg) {
if (msg.what == OPEN_ANNOTATION) {
new YourPopup(context, msg);
}
}
}
在创建弹出窗口之前,您应该用xml设计自己的布局(如果需要,也可以通过编程方式创建)。为了理解代码,我应该提到我调用我的布局popup\u layout
。
此外,您应该向glsurfaceview的布局中添加一个空布局(它应该在宽度和高度上填充父布局),比如说一个线性布局,它将容纳弹出窗口。我称之为popumpoolder
YourPopup.java
@Override
public void onDrawFrame(GL10 gl) {
.... code that displays the mesh ...
if(userRequestedPopup) {
Message message = new Message();
message.what = DialogHandler.OPEN_ANNOTATION;
// Here you can create a Bundle in order to pass more data inside the Message
dialogHanlder.sendMessage(message);
userRequestedPopup = false;
}
....
}
public Popup(Context context, Message message) {
this.context = context;
Activity parent = (Activity) context;
// here you can have the instance of the holder from glSurfaceView
LinearLayout parentLayout = (LinearLayout) parent.findViewById(R.id.popupHolder);
// inflate your custom popup layout or create it dynamically
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.popup_layout, null);
// Now you should create a PopupWindow
PopupWindow popupWindow = new PopupWindow(view,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
// you can change the offset values or the Gravity. This will diaply the popup in the center
// of your glSurfaceView
popupWindow.showAtLocation(parentLayout, Gravity.CENTER, 0, 0);
}
我想这就是你需要的,因为这个解决方案对我来说很好
希望我能帮助…为弹出窗口创建一个XML,然后在Java文件中使用以下代码:
public void popupWindow() {
PopupWindow pw;
LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup_window, (ViewGroup) findViewById(R.id.txtPusdNotR));
pw = new PopupWindow(layout, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
// Get your Buttons and other tags here
}