• 将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);
    
        }
  • 相关阅读:
    jquery操作select(取值,设置选中)
    POST 服务测试PHP页面
    Web开发者不容错过的20段CSS代码(二)
    Web开发者不容错过的20段CSS代码(一)
    Word排版技巧
    需求分析的故事——如何练就需求分析的火眼金晴?
    如何来书写需求说明书
    Struts配置文件阐释
    做需求要会问为什么和需求场景
    跑通并调试第一个Java Struts程序
  • 原文地址:https://www.cnblogs.com/ct732003684/p/2846472.html
Copyright © 2020-2023  润新知