开发者

android how to add two views into an activity

开发者 https://www.devze.com 2023-03-14 13:05 出处:网络
I wanna add one xml file and one class which extends View to an single activity so that it work simultaneously.

I wanna add one xml file and one class which extends View to an single activity so that it work simultaneously. like below,

  1. main.xml
  2. private static class GraphicsView extends View

MyActivity

onCreate()
{
 RelativeL开发者_Python百科ayout ll= new RelativeLayout(this);
ll.addView(new GraphicsView(this));
ll.--------->how to add main.xml here?
 setContentView(ll);// so that i can write like this
}

please solve this. Thank you


use layout inflater. Do some thing like this....

LayoutInflater inflater = (LayoutInflater) adapterContext
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = inflater.inflate(R.layout.your_xmls, null);  

Now add this view to ll.

ll.addView(view)...

Thanks.

0

精彩评论

暂无评论...
验证码 换一张
取 消