我想在当前视图中启动一个新的活动意图!我该怎么做?

最佳答案

经过一番努力,我找到了。我把我的第一个布局这样!

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout android:id="@+id/contentViewLayout"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/white"
        android:layout_marginBottom="56dip"/>

        <HorizontalScrollView
            android:scrollbarSize="2dip"
            android:layout_alignParentBottom="true"
            android:layout_width="fill_parent"
            android:background="@drawable/background" android:layout_height="56dip">

    </HorizontalScrollView>
</RelativeLayout>

当我必须开始新的活动时,我使用以下代码…
public class MainActivityWithTabbar extends ActivityGroup implements OnClickListener{

    public LocalActivityManager activityManager;
    public LinearLayout contentViewLayout;
    public LinearLayout.LayoutParams contentViewLayoutParams;
    private Context context;
    public Intent nextActivit;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        activityManager = getLocalActivityManager();
        setContentView(R.layout.mainActivityLayout);
        contentViewLayout = (LinearLayout)findViewById(R.id.contentViewLayout);
        contentViewLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

        nextActivit = new Intent(this, NextActivity.class);
        startGroupActivity("activity1", nextActivit);

    }

    public void startGroupActivity(String id, Intent intent)
    {
        contentViewLayout.removeAllViews();

        View view = activityManager.startActivity(id, intent).getDecorView();
        contentViewLayout.addView(view, contentViewLayoutParams);
    }
}

所以在这种情况下它是有效的…

10-07 15:36