OpenGL和Android的相对布局
我已经试着问了这个问题相对布局编码,但第一次尝试不是很清楚
I already tried asking this question at Relative layout Coding, but that first attempt was not very clear.
我想创造超过 GLSurfaceView
一个相对布局,但布局必须是这样的:
I would like to create a relative layout over GLSurfaceView
but the layout must look like this:
<RelativeLayout
android:id="@+id/View1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@raw/gi"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="64px"
android:layout_height="64px"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/b1" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="64px"
android:layout_height="64px"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView1"
android:src="@drawable/b2" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="64px"
android:layout_height="64px"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView2"
android:src="@drawable/b3" />
</RelativeLayout>
不过,如果我code这就像他们说,在它的工作原理的答案,但图像依然放在彼此的上面。 (我用的getId功能addrules)
However, if I code it like they say in the answers it works but the images are still put on top of each other. (I used the getId functions to addrules)
所以,我想加入整个XML文件,并按照这种方式,但任何时候我加载XML应用程序停止。这里的大多数code:
So I'm thinking of adding the whole xml file and work that way but any time I load an xml the app stops. Here's most of the code:
public class HelloWorld extends Activity {
...
protected void onCreate(Bundle savedInstanceState) {
....
opengl = new GLSurfaceView(getApplication());
opengl.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE};
EGLConfig[] configs = new EGLConfig[1];
int[] result = new int[1];
egl.eglChooseConfig(display, attributes, configs, 1, result);
return configs[0];
}
});
renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(opengl);
addContentView(findViewById(R.id.View1), new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT));
请记住,如果没有为 addContentView
应用程序作品的最后一次通话。
Bear in mind that without the last call to addContentView
the app works.
它看起来像我要回答我的问题。
It looks like I'm gonna answer my own question.
而不是addcontentview中添加以下
instead of addcontentview i added the following
gi=new RelativeLayout(this);
View view;
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.gi, null);
hud.addView(view);
addContentView(gi, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
,因此我succeded中加入上述glsurface视图中的整个XML文件。
and as such I succeded in adding a whole xml file above the glsurface view.
但我对如何让每个孩子的ID在r.layout.gi现在不知道。比方说,我想改变R.id.imageView1 ??????????????的图片
But I am wondering now on how to get an id of each child in r.layout.gi. Let's say I want to change a picture of R.id.imageView1 ??????????????
没有任何人知道如何与目前的code做到这一点?
Does Anybody know how to do this with the current code?