我已经试过在Relative layout Coding处询问这个问题,但是第一次尝试并不是很清楚。OpenGL和Android相对布局
我想在GLSurfaceView
创建一个相对布局,但布局必须是这样的:
<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>
但是,如果我的代码它,就像他们在它的工作原理回答说,但图片尚未提上彼此顶部。 (我用getId函数进行addrules)
所以我正在考虑添加整个XML文件并以这种方式工作,但任何时候我加载一个XML应用程序停止。这里的大部分代码:
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
应用作品。
看起来我要回答我自己的问题。 代替addcontentview添加以下 GI =新的RelativeLayout(本); 查看查看; LayoutInflater inflater =(LayoutInflater)getApplicationContext()。getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.gi,null); hud.addView(view); \t \t addContentView(gi,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT)); – user1398593
因此我成功地在glsurface视图上添加了一个完整的xml文件。 但我现在想知道如何获得r.layout.gi中每个孩子的ID。假设我想改变一张R.id.imageView1的图片?????????????? (特别感谢http://stackoverflow.com/questions/2335813/how-to-inflate-one-view-with-an-layout) – user1398593
评论并非答案。如果你想回答自己的问题,实际上*通过使用页面底部的“发布你的答案”按钮来回答它。 –