0

I already tried asking this question at Relative layout Coding, but that first attempt was not very clear.

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>

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)

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));

Bear in mind that without the last call to addContentView the app works.

Community
  • 1
  • 1
  • It looks like I'm gonna answer my own question. 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)); – user1398593 May 26 '12 at 13:28
  • and as such I succeded in adding a whole xml file above the glsurface view. 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 ?????????????? (Special thanks to http://stackoverflow.com/questions/2335813/how-to-inflate-one-view-with-an-layout) – user1398593 May 26 '12 at 13:29
  • 1
    Comments are not answers. If you want to answer your own question, actually *answer* it by using the "Post Your Answer" button at the bottom of the page. – Nicol Bolas May 26 '12 at 13:46
  • i couldn't answer for another 10 hours so i put it here, anyway back to my question how do I change the picture at r.id.imageview1 at this new inflated layout – user1398593 May 26 '12 at 18:37
  • If you're using OpenGL, you should be using GLSurfaceView, not RelativeLayout/LinearLayout – Codeman May 29 '12 at 15:45

2 Answers2

0

It looks like I'm gonna answer my own question.

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));

and as such I succeded in adding a whole xml file above the glsurface view.

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 ??????????????

Does Anybody know how to do this with the current code?

0

I know this worked for me with the normal FrameLayout.

    TextView counter = new TextView(getApplicationContext());
    counter.setBackgroundResource(R.drawable.counter);
    counter.setTextSize(50);
    counter.setTypeface(null, Typeface.BOLD);
    counter.setText(" 000");
    addContentView(counter, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
DrBrad
  • 305
  • 2
  • 13