如何在 Android 中的 MapView 上覆盖 GLSurfaceView? [英] How to overlay GLSurfaceView over a MapView in Android?
问题描述
我想在 android 中创建一个简单的基于地图的应用程序,我可以在其中显示我当前的位置.我想在 MapView 上覆盖 GLSurfaceView,而不是在 MapView 上覆盖一个简单的图像来表示位置.但我不知道如何实现这一点.有没有办法做到这一点?请任何知道解决方案的人帮助我.
I want to create a simple Map based application in android ,where i can display my current position.Instead of overlaying a simple Image on the MapView to represent the position, i want to overlay the GLSurfaceView on the MapView. But i don't know how to achieve this. Is there any way to do that?. Please anybody knows the solution help me.
推荐答案
在查看文档并意识到 MapView
extends ViewGroup
之前,我遇到了类似的问题,因此覆盖 GlSurfaceView
实际上最终变得非常简单.
I was stuck on a similar problem until I looked at the documentation and realized that MapView
extends ViewGroup
, so overlaying a GlSurfaceView
actually ends up being pretty trivial.
MapView.addView(...)
和 MapView.LayoutParams
允许您做一些非常有用的事情,例如在特定位置放置 View
GeoPoint
在地图上.
MapView.addView(...)
and MapView.LayoutParams
allow you to some pretty useful things like place a View
at a specific GeoPoint
on the map.
这就是我所做的:
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
MapView map_view = (MapView) findViewById(R.id.map_view);
CustomGlView gl_view = new CustomGlView(this);
// This is where the action happens.
map_view.addView(gl_view, new MapView.LayoutParams(
MapView.LayoutParams.FILL_PARENT,
MapView.LayoutParams.FILL_PARENT,
0,0,
MapView.LayoutParams.TOP_LEFT
)
);
}
此外,还可以按照上述解决方案的规定进行操作.我对 GlSurfaceView 进行了子分类,所以我的看起来略有不同:
Plus also do what the solution above states. I sub-classed GlSurfaceView, so mine looks slightly different:
public CustomGlView(Context context) {
super(context);
YourCustomGlRenderer renderer = new YourCustomGlRenderer();
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
setRenderer(renderer);
getHolder().setFormat(PixelFormat.TRANSLUCENT);
// Have to do this or else
// GlSurfaceView wont be transparent.
setZOrderOnTop(true);
}
这篇关于如何在 Android 中的 MapView 上覆盖 GLSurfaceView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!