在一个主界面中做Activity切换一般都会用TabActivity,使用方便,Activity互相之间相对独立,但是可定制性不强,而且修改起来很麻烦。当然也可以把layout分开,把逻辑代码全写在主界面的逻辑代码中,但是很明显可维护性相当差,这里通过 ActivityGroup来解决这个问题。
package com.ffly.demo;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ScrollView;
public class MainActivity extends ActivityGroup implements OnClickListener {
private ScrollView mScroll = null;
private ImageView mImgBtn1 = null;
private ImageView mImgBtn2 = null;
private ImageView mImgBtn3 = null;
private LocalActivityManager mActivityManager = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mScroll = (ScrollView) findViewById(R.id.containerBody);
mImgBtn1 = (ImageView) findViewById(R.id.btnModule1);
mImgBtn2 = (ImageView) findViewById(R.id.btnModule2);
mImgBtn3 = (ImageView) findViewById(R.id.btnModule3);
mImgBtn1.setOnClickListener(this);
mImgBtn2.setOnClickListener(this);
mImgBtn3.setOnClickListener(this);
mActivityManager = getLocalActivityManager();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnModule1:
mScroll.removeAllViews();
mScroll.addView(mActivityManager.startActivity("",
new Intent(this, ActivityTest1.class)).getDecorView());
break;
case R.id.btnModule2:
mScroll.removeAllViews();
mScroll.addView(mActivityManager.startActivity("",
new Intent(this, ActivityTest2.class)).getDecorView());
break;
case R.id.btnModule3:
break;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:gravity="center_horizontal"
android:background="#fc9999" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/cust_title" android:textColor="@android:color/white"
android:textSize="28sp" android:text="ActivityGroup" android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
</LinearLayout>
<!-- 中间动态加载View -->
<ScrollView android:measureAllChildren="true" android:id="@+id/containerBody"
android:layout_weight="1" android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ScrollView>
<LinearLayout android:background="@android:color/black"
android:layout_gravity="bottom" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<!-- 功能模块按钮1 -->
<ImageView android:id="@+id/btnModule1" android:src="@android:drawable/ic_dialog_dialer"
android:layout_marginLeft="7dp" android:layout_marginTop="3dp"
android:layout_marginBottom="3dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- 功能模块按钮2 -->
<ImageView android:id="@+id/btnModule2" android:src="@android:drawable/ic_dialog_info"
android:layout_marginLeft="7dp" android:layout_marginTop="3dp"
android:layout_marginBottom="3dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- 功能模块按钮3 -->
<ImageView android:id="@+id/btnModule3" android:src="@android:drawable/ic_dialog_alert"
android:layout_marginLeft="7dp" android:layout_marginTop="3dp"
android:layout_marginBottom="3dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
分享到:
相关推荐
使用ActivityGroup来切换Activity和Layout
Android开发—使用ActivityGroup来切换Activity和Layout
Android开发—使用ActivityGroup来切换Activity和Layout.pdf
ActivityGroup的用法,头部和底部为固定布局中间动态显示界面 并在中间布局实现手势滑动效果,自定义SlidingDrawer(抽屉)效果,在ActivityGroup里执行跳转等功能。至于在Android在ActivityGroup里执行跳转详细介绍 ...
在子Activity中,我们使用GridView来展示数据。通过ViewFlipper的setDisplayedChild方法,我们可以轻松地在不同的选项卡之间进行切换。 此外,该项目还提供了丰富的自定义选项,包括选项卡的样式、颜色、字体等。您...
NULL 博文链接:https://fanhongtao.iteye.com/blog/1430893
ActivityGroup之Activity内跳转和外跳转
android中tabhost和ActivityGroup的组合使用,特别是对多个Activity之间的跳转,压栈出战的管理,很有帮助。
ActivityGroup之activity内跳转和外跳转的源码
Gallery+ActivityGroup实现滑动tab独立的Activity
ActivityGroup和ViewPager组合实现微信模仿,里面包含下拉刷新需要导入的包
ActivityGroup 使用实现tab分页标签,保存Activity状态、使用子Activity的Menu
ActivityGroup 多个activity页面返回 子activity menu设置
activitygroup底部菜单切换
很多客户端软件和浏览器软件都喜欢用Tab分页标签来搭建界面框架。读者也许会马上想到使用TabHost 与 TabActivity的组合,其实最常用的不是它们,而是由GridView与ActivityGroup的组合。每当用户在GridView选中一项,...
用ActivityGroup实现的activity栈,类似IOS的UINavigationController
切换activity,使用ActivityGroup 和ViewPager结合,非常简单易懂
用ActivityGroup解决TabHost中多个Activity跳转问题 参见http://hkp2008.iteye.com/blog/1185482
android开发中使用ActivtiyGroup和ViewFlipper实现多个Activity之间的滑屏切换,用GestureDetector实现手势滑动
NULL 博文链接:https://1002878825-qq-com.iteye.com/blog/1812628