gpt4 book ai didi

android - 如何在同一 View 中启动子 Activity ?

转载 作者:搜寻专家 更新时间:2023-11-01 08:16:30 26 4
gpt4 key购买 nike

我想在我当前的 View 中开始一个新的 Activity Intent !我该怎么做?

最佳答案

经过一番搜索,我找到了。我以这种方式放置我的第一个布局!

<?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>

当我必须在其中开始新 Activity 时,我使用以下代码...

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);
}
}

所以在这种情况下它可以工作....

关于android - 如何在同一 View 中启动子 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4096633/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com