问题
I'm trying to do an application where there is a background, and with canvas i draw some lines. But there is a problem. Because to make background and other graphicals things i use a .xml file named "activity_main.xml" and after i do
setContentView(R.layout.activity_main); to activate it. But when i draw the line i must use this:
drawView = new DrawView(this)
setContentView(drawView);
Where drawView is the class that allow me to draw the line. So the first setContentView result useless and i don't know how to do some change (for examples the background) if i had to work with drawView!
"You have no way to add a DrawView in your activity_main layout ?" Sorry, i suppose yes, but i don't know how to do.
回答1:
You can add your view to your layout like this:
ViewGroup layout = (ViewGroup) findViewById(R.id.your_layout_id);//your container's id in your activity_main.xml
drawView = new DrawView(this);
layout.addView(drawView);
回答2:
Why not just add the DrawView to your existing layout with addView()?
You'll have to position it correctly of course, probably within a RelativeLayout.
来源:https://stackoverflow.com/questions/20274104/android-how-to-use-2-layout