AddContentView simplified
Welcome to inphamousdevelopment.com! You were probably directed here from my portfolio site, inphamous.com, or by some miracle you were looking for some android code on Google and you happened to stumble here. Basically this site is a way I’m contributing back to the internet by sharing the code I’ve created and found to help your android producing experience easier.
Today, for a first post, I will make a simple yet demanded contribution. First, let me type out all of the searches I made before I got close to my answer
addContentView help, addContentView Android, addContentView Code Android, Adding a xml layout onto a canvas android, how to inflate a view with an xml file, multiple layout xml android, etc, etc.
The list goes on, next time I will actually better document what I searched for, so that hopefully those same searches will direct you here! In any case, by reading those searches, maybe you can see what I wanted to do. I want to draw a couple of buttons from an xml layout onto a canvas. This solution will work with drawing any xml layout onto anything else however.
LayoutInflater mInflater = getLayoutInflater(); View mView; mView = mInflater.inflate(R.layout.extra_layout, null); getWindow().addContentView(tmpView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
Alternatively, if you want the code to be a little slimmer, just put the inflater return directly into the addcontent function, as so
getWindow().addContentView(getLayoutInflater().inflate(R.layout.extra_layout, null), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
This code goes into your onCreate(Bundle whateever), preferably right underneath where you just called “setContentView(R.layout.main);”
If you found this helpful, leave a comment! I make no claim that this is the best implementation for this idea, but it works!
-Kevin


It was hopeless.. Thank you, man!
Enormously helpful. I was banging my head trying to do a simple grid with axes and gridlines. This got me over the hump, thanks!
holy crap this is what Ive been stuck on for too long thank you soooo much!!!
its good but how to add an extra edittext button to present view
hi what should ‘layout.extra_layout’ contain button?
can it contain image?
Thanks dude, I’ve been looking for this for so long… I was starting to think this was not possible. Thank you !