如何膨胀FrameLayout?
我有线性布局,我想将 FrameLayout 填充到其中。你知道如何做到吗?是否可以?我仍然收到没有找到适合充气的方法的错误,
谢谢
编辑: 回答我自己:
LinearLayout ll=(LinearLayout) findViewById(R.id.linear);
final LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FrameLayout frml = (FrameLayout)inflater.inflate(R.layout.frame,null);
frml.setId(10101010);
frml.setBackgroundColor(Color.RED);
ll.addView(frml);
I have linear Layout and I want to inflate FrameLayout into it. Do you know, how it can be done? Is it possible? I am still getting errors of No Suitable Method Found For Inflate
Thanks
Edit:
answering myself:
LinearLayout ll=(LinearLayout) findViewById(R.id.linear);
final LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FrameLayout frml = (FrameLayout)inflater.inflate(R.layout.frame,null);
frml.setId(10101010);
frml.setBackgroundColor(Color.RED);
ll.addView(frml);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获取 LayoutInflater 实例,您需要将其作为这样的服务获取
然后您可以使用它来膨胀 FrameLayout 并将其添加到 LinearLayout > 像这样
不要忘记像这样设置 FrameLayout 的布局宽度和高度
有关 LayoutInflater 的更多信息 访问此链接
To get the LayoutInflater instance you need to get it as a service like this
Then you can use it to inflate the FrameLayout and add it to the LinearLayout like this
And don't forget to put the layout width and height for your FrameLayout like this
For more infromation about the LayoutInflater visit this link