动态替换Fragment
我最初在 coderanch 上发布了这个问题,但没有得到回复,所以我在这里试试运气。
我试图通过单击fragmen2 中定义的“更改片段”按钮来用fragment3 替换fragment1。 Fragment3不会完全取代Fragment1。相反,它会将自己排列在 Fragment1 中的文本下方。我正在做一些愚蠢的事情,我可以使用一些指针。我已在此处包含代码和输出错误屏幕截图(灰色区域fragment3没有完全覆盖白色区域fragment1)。感谢您的指点。
我尝试在这里上传并格式化所有代码,但由于某种原因,它告诉我我的代码没有缩进 4 个空格,并且我的输出图像不是 jpeg 图像。所以我把代码发布在 http://www.coderanch.com/t/556305/Android /移动/动态替换片段 抱歉,我无法将其发布在这里。
在我的输出中,我看到fragment3.xml 并未完全重叠fragment1.xml。任何帮助将不胜感激。谢谢
I originally posted this queston on coderanch, but I didn't get responses, so I am trying my luck here.
I am trying to replace fragment1 with fragment3 by clicking on a 'Change Fragment' Button defined in fragmen2. Fragment3 will not fully replace Fragment1 completely. Instead it lines itself up underneath the text in Fragment1. I am doing something silly and I could use some pointers. I have included the code here and the output error screenshot (the gray area fragment3 doesn't completely overlay the white area fragment1). Thanks for any pointers.
I tried to upload and format all the code here, but for some reason, it tells me my code is not indented with 4 spaces and my output image is not a jpeg image. So I got the code posted at
http://www.coderanch.com/t/556305/Android/Mobile/Dynamically-replacing-Fragments
Sorry I couldn't post it here.
On my output, I see that fragment3.xml doesn't completely overlap fragment1.xml. Any help would be sincerely appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该使用
R.id.fragment1
。您应该为FrameLayout
提供一个 Id,并将FrameLayout
的内容替换
为fragment2。You should not use
R.id.fragment1
. You should give an Id for theFrameLayout
andreplace
the contents of theFrameLayout
with fragment2.