android使用activitygroup和Scrollview的方法



其中主要的代码就是:

 //跳转到相应的界面中,获得界面的
Window window  = getLocalActivityManager().startActivity("11",new Intent(ActivityGroupTest1.this,Activity1.class));
scrollView.removeAllViews();
//把activity转化为VIEW,然后放在scrollview中
scrollView.addView( window.getDecorView() );


主界面:

package com.activity.group.test1;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ScrollView;

import com.example.androidinterviewtest1.R;

public class ActivityGroupTest1 extends ActivityGroup
{
    
    Button button1;
    Button button2;
    ScrollView scrollView;
    

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        
        
        //初始化组件
        System.out.println("ActivityGroupTest1 onCreate");
        setContentView(R.layout.activity_group);
        scrollView = (ScrollView)findViewById(R.id.content);
        button1 = (Button)findViewById(R.id.btu1);
        
        //设置监听
        button1.setOnClickListener( new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //跳转到相应的界面中,获得界面的
                Window window  = getLocalActivityManager().startActivity("11",new Intent(ActivityGroupTest1.this,Activity1.class));
                scrollView.removeAllViews();
                //把activity转化为VIEW,然后放在scrollview中
                scrollView.addView( window.getDecorView() );
            }
        });
        button2 = (Button)findViewById(R.id.btu2);
        button2.setOnClickListener( new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {

                Window window  = getLocalActivityManager().startActivity("22",new Intent(ActivityGroupTest1.this,Activity2.class));
                scrollView.removeAllViews();
                scrollView.addView( window.getDecorView() );
            }
        });
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        System.out.println("ActivityGroupTest1 onDestroy");
    }

    @Override
    protected void onPause()
    {
        super.onPause();
        System.out.println("ActivityGroupTest1 onPause");
    }

    @Override
    protected void onResume()
    {
        super.onResume();
        System.out.println("ActivityGroupTest1 onResume");
    }

    @Override
    protected void onStop()
    {
        super.onStop();
        System.out.println("ActivityGroupTest1 onStop");
    }
    
    
    
    
    
}



布局文件:

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

    <!-- 界面的文字显示 -->
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="hello my name is ljz"
        android:textSize="18dp" /> 

    <!-- 用户保存用户的界面 -->
    <ScrollView
        android:id="@+id/content"
        android:layout_width="fill_parent"
        android:layout_height="350dp" >
        <!-- 初始化显示的数据界面 -->
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:text="dasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\ndasdasd\n"/>
    </ScrollView>

    <!-- 底部的按钮 -->
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btu1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="btu1" />

        <Button
            android:id="@+id/btu2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="btu2" />
    </LinearLayout>

</LinearLayout>


你可能感兴趣的:(android,layout,Class,import,button,encoding)