(note that I’m a total beginner in android programming)
I have a class that derives from GLSurfaceView.
What I would like is to place some views (image,text) on top of it.
I managed to get the text view to position properly by using textView.setPadding(300,0,0,0);
The problem is that I cannot get the image view to position properly. I’ve tried imageView.layout(), imageView.setPadding().
Here is the code:
ImageView imageView=new .... // Create and set drawable
// Setting size works as expected
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(200,200);
imageView.setLayoutParams(lp);
surfaceView = new MySurfaceViewDerivedFromOpenGLSurface(...);
setContentView(surfaceView);
addContentView(textView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
addContentView(textView2, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
addContentView(imageView, lp); // Add the image view
Is it even possible to position it properly this way without specifing the stuff in the XML file?
I saw an example in the sdk dev website that shows how to create views on the openGL surface view, but the problem is that I have a derived class and I don’t know if I can specify it in the XML file (I have 0% experience in the XML, Eclipse handled everything for me so far).
You’ll save a ton of headaches later by learning how to use xml layout. Specifying a layout for a custom view tripped me up too. This is how it works:
So a really simple vertical layout for your app would be:
You can get a reference to anything in your layout files as long as there’s an id: