我想在屏幕上同时显示两个不同的活动。我的印象是人们可以使用ActivityGroup
来实现它。是这样吗?
我试过这种方式:
layout = (ListView) findViewById(R.id.wrapper_layout);
LocalActivityManager mgr = getLocalActivityManager();
Intent intent = new Intent(this, BenchMarker.class);
Window w = mgr.startActivity("BenchMarkerA", intent);
View wd = w != null ? w.getDecorView() : null;
if(wd != null) {
layout.addView(wd);
}
但NullPointerException
ActivityThread.performLaunchActivity()
答案 0 :(得分:1)
是的,我可以。这些天我会写下解决方案。
这是怎么做的。
首先,您需要一个合适的布局,例如 res / layout / multiview.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/multiview_layout">
<LinearLayout android:id="@+id/my_view_1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
</LinearLayout>
<LinearLayout android:layout_height="fill_parent"
android:layout_width="fill_parent" android:layout_weight="1"
android:id="@+id/my_view_2">
</LinearLayout>
</LinearLayout>
在你的主要活动中将扮演启动者的角色:
public class MyMultiViewActivity extends ActivityGroup {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.multiview);
layout = (LinearLayout) findViewById(R.id.multiview_layout);
layout_s1 = (LinearLayout) findViewById(R.id.my_view_1);
layout_s2 = (LinearLayout) findViewById(R.id.my_view_2);
LocalActivityManager mgr = getLocalActivityManager();
layout_s1.addView((mgr.startActivity("MyOtherActivityInstance1", new Intent(this, MyOtherActivity.class))).getDecorView());
layout_s2.addView((mgr.startActivity("MyOtherActivityInstance2", new Intent(this, MyOtherActivity.class))).getDecorView());
}
LinearLayout layout;
LinearLayout layout_s1;
LinearLayout layout_s2;
}