user2426316
user2426316

Reputation: 7331

How should I add elements to a custom camera android application?

my android app uses a custom camera. I just have a framelayout (full screen) in my xml layout file to which i programmatically add a surfaceview that contains the camera preview.

Now I would like to add some buttons to my frame layout. I know that i could just add those buttons all programmatically, but is there a nicer way to do it. I mean, could I create something like a mask / layout that contains some buttons and that I then programmatically add to my frame layout?

How do professional app makers do that? I just want to know all this so that I can keep a good design.

Thank you so much!

Upvotes: 1

Views: 1954

Answers (2)

Vikram
Vikram

Reputation: 51571

Create your layout xml file. From the information you have given, the base will be a FrameLayout. Place buttons and other widgets wherever you need to. As an example, say you place 3 buttons inside the FrameLayout: b1, b2 and b3.

When the SurfaceView is added, the buttons will not be visible. Do this to show them on top of the SurfaceView:

// Initially

frameLayout = (FrameLayout) findViewById(R.id.framelayout_id_from_xml_file);

b1 = (Button) findViewById(R.id.button_id_from_xml_file_1);

b2 = (Button) findViewById(R.id.button_id_from_xml_file_2);

b3 = (Button) findViewById(R.id.button_id_from_xml_file_3);

....
....
....

// create a SurfaceView and add it to the framelayout

frameLayout.add(sufaceView);

// now, remove the buttons and add them again

frameLayout.removeView(b1);
frameLayout.addView(b1);

frameLayout.removeView(b2);
frameLayout.addView(b2);

frameLayout.removeView(b3);
frameLayout.addView(b3);

Upvotes: 0

Related Questions