Android的:如何用2布局 [英] Android: How to use 2 layout
问题描述
我试图做一个应用程序,其中有一个背景,并用帆布我画一些线条。但是有一个问题。由于制作背景等graphicals事情,我使用,并命名为activity_main.xml一个.xml文件后,我做的
的setContentView(R.layout.activity_main);
来激活它。但是,当我划清界线,我必须这样做:
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);
在哪里drawView函数的类,它让我划清界线。 所以第一的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!
你有没有办法添加drawView函数在activity_main布局? 对不起,我想是的,但我不知道该怎么办。
"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.
推荐答案
您可以将您的视角以这样的布局:
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);
这篇关于Android的:如何用2布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!