Android 上使用 Fragment 的选项卡,但位于另一个布局内
我正在创建具有主要活动的表格布局的 Android 应用程序,并且该部分工作完美...现在,想法是在现有组件下方添加应用程序的另一部分,但现在我必须在那里放置一个选项卡式布局。嗯,当我尝试运行该部分时,该部分也可以完美运行。但是我必须做什么才能将这两者混合在一起,使这两者在同一个屏幕上显示在另一个下面。
我的主要代码是:
package my.android;
import android.os.Bundle;
public class MyActivity extends FragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
我对所有选项卡都有不同的布局文件,并且我有我按照此处的教程创建的 TabsActivity 类: http://thepseudocoder.wordpress.com/2011/ 10/04/android-tabs-the-fragment-way/
那么如何将一些 TabsActivity ta 对象添加到 MyActivity 中?重要的是低于此内容。提前谢谢...
I'm creating android app that has table layout for the main activity, and that part works perfectly... Now, the idea was to add another part of an app below the existing components, but now I have to put a tabbed layout there. Well, that part also works perfectly when I try to run just that. But what do I have to do to mix those two in such a way that these two show up one below another on the very same screen.
My main code is:
package my.android;
import android.os.Bundle;
public class MyActivity extends FragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
I have different layout files for all the tabs and I have my TabsActivity class I have created following the tutorial here:
http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/
So how do I add some TabsActivity ta object to the MyActivity? And it is important to be below the content of this. Thaks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
理想情况下,这可以使用嵌套片段来完成,但 Android 尚不支持。这就留下了已弃用的 ActivityGroup 类。您将需要一个顶级活动来扩展 ActivityGroup 并启动这两个活动。
以下是启动活动并获取他们的意见的方法:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
编辑:下面是一个更完整的解决方案。
这是顶级活动的布局:
这是顶级类:
您可以根据需要添加任意数量的嵌入活动。您甚至可以嵌套嵌入式活动,但请注意性能可能成为一个因素。我们用它来支持动态状态列。
就我个人而言,我认为 ActivityGroup 仍然有用,并希望 Google 改变主意,不再弃用它。
Ideally this would be done using nested Fragments, but Android doesn't support that yet. That leaves the deprecated ActivityGroup class. You'll need a top level activity that extends ActivityGroup and launches the two activities.
Here is how you launch the activities and get their views:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Edit: Below is a more complete solution.
This is the layout for the top level activity:
Here is the top level class:
You can add as many embedded activities as you want. You can even nest embedded activities, but be aware that performance could become a factor. We use this to support a dynamic status column.
Personally, I think there is still a use for the ActivityGroup and hope that Gooogle changes their mind about deprecating it.