Currently I understand I can create a XML Layout and pass that to setContentView(…), or I can pass a Customized view to setContentView(…).
But what if I want to combine the elements of both? Is it possible to use a layout first, then to programmatically add to the UI via java code?
For example: How could I create a view that uses an Asset background picture with an added loading widget on top?
ADDED INQUIRY: Right now and I think of a View and a Layout as two things for setContentView to display. But can a View hold a layout within it to be displayed?
Yes its possible to set an XML layout with setContentView(), and programmatically add more views/widget to that layout. Here’s a short example.
main.xml
TestActivity.java
The result is an activity with background_image.png as background, and two textviews with text 😉
You can add any type of view (TextView, EditText, ImageView, Buttons etc) this way.