zoukankan      html  css  js  c++  java
  • 将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);
    
        }
  • 相关阅读:
    201671010417 金振兴 词频统计软件项目报告
    201671010417 金振兴 实验三 作业互评与改进
    读构建之法提出的问题
    201671010422 结对项目报告
    201671010422 马亮 实验三作业互评与改进报告
    实验十四 个人学习总结
    201671010422 词频统计软件项目报告
    201671010423马丽莎 《英文文本统计分析》结对项目报告
    201671010423 词频统计软件项目报告
    201671010423马丽莎 实验三作业互评与改进报告
  • 原文地址:https://www.cnblogs.com/ct732003684/p/2846472.html
Copyright © 2011-2022 走看看