将activity转化成view
package com.ct.views; import android.app.Activity; import android.app.ActivityGroup; import android.app.LocalActivityManager; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.view.Window; public class MainActivity extends ActivityGroup { /** Called when the activity is first created. */ private LocalActivityManager mLocalActivityManager; private View lyFirst; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); init(); } private void init(){ mLocalActivityManager = getLocalActivityManager(); lyFirst = activityToView(MainActivity.this,new Intent(MainActivity.this,FirstActivity.class)); setContentView(lyFirst); } public View activityToView(Context parent, Intent intent) { final Window w = mLocalActivityManager.startActivity("id", intent); final View wd = w != null ? w.getDecorView() : null; if (wd != null) { wd.setVisibility(View.VISIBLE); wd.setFocusableInTouchMode(true); ((ViewGroup) wd) .setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); } return wd; } }
或者另一种方式
用tabActivity
一:布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/main_bg" android:orientation="vertical" android:id="@+id/layout_show"> <include android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" layout="@layout/title" > </include> <TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginTop="2dip"> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0" android:background="@drawable/bg_tab" android:paddingLeft="15dip" android:paddingRight="15dip" android:paddingBottom="2dip"/> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:gravity="center" android:fadingEdge="none"></FrameLayout> </LinearLayout> </TabHost> </LinearLayout>
二:activity
extends TabActivity
private void addTabHost() {
tabHost = (AnimationTabHost) getTabHost();
tabHost.addTab(tabHost.newTabSpec(TAB_SENT).setIndicator(TAB_SENT)
.setContent(new Intent(this, SendMessageActivity.class)));
tabHost.addTab(tabHost.newTabSpec(TAB_RECEIVE)
.setIndicator(TAB_RECEIVE).setContent(
new Intent(this, ReceiveMessageAcitvity.class)));
tabHost.addTab(tabHost.newTabSpec(TAB_RUBBISH)
.setIndicator(TAB_RUBBISH).setContent(
new Intent(this, RubbishMessageActivity.class)));
tabHost.addTab(tabHost.newTabSpec(TAB_DRAFTS).setIndicator(TAB_DRAFTS)
.setContent(new Intent(this, DraftsBoxActivity.class)));
tabHost.setCurrentTab(1);
tabHost.setOpenAnimation(true);
}
posted on 2013-01-05 17:58 732003684 阅读(4951) 评论(0) 编辑 收藏 举报