android-ActivityGroup

来源:互联网 发布:淘宝企业店铺避税提现 编辑:程序博客网 时间:2024/05/16 12:20

有些API还没用呢,就已经过时了。。。还是了解下吧。


效果:



代码:

public class MainActivity extends ActivityGroup {private Class<?>[] classNames = { FirstActivity.class,SecondActivity.class, ThirdActivity.class };@SuppressWarnings("deprecation")private LocalActivityManager lam = getLocalActivityManager();private LinearLayout bodyView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);bodyView = (LinearLayout) findViewById(R.id.body);}private void loadActivity(Class<?> activity) {bodyView.removeAllViews();View view = lam.startActivity(activity.toString(),new Intent(MainActivity.this, activity).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();bodyView.addView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT));}public void onBtn1Click(View v) {loadActivity(classNames[0]);}public void onBtn2Click(View v) {loadActivity(classNames[1]);}public void onBtn3Click(View v) {loadActivity(classNames[2]);}}

布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="com.example.activitygroup.MainActivity" >    <LinearLayout        android:id="@+id/header"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_alignParentTop="true"        android:layout_weight="0.4"        android:orientation="vertical" >        <TextView            android:layout_width="match_parent"            android:layout_height="match_parent"            android:background="#005"            android:gravity="center"            android:text="ActivityGroup Demo"            android:textColor="#f00"            android:textSize="24sp" />    </LinearLayout>    <LinearLayout        android:id="@+id/body"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="5"        android:background="#55f"        android:gravity="center"        android:orientation="vertical" >    </LinearLayout>    <LinearLayout        android:id="@+id/bottom"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="0.7"        android:background="#555"        android:orientation="horizontal" >        <Button            android:id="@+id/button1"            android:layout_width="0dp"            android:layout_height="wrap_content"            android:layout_weight="1"            android:onClick="onBtn1Click"            android:text="Button1" />        <Button            android:id="@+id/button2"            android:layout_width="0dp"            android:layout_height="wrap_content"            android:layout_weight="1"            android:onClick="onBtn2Click"            android:text="Button2" />        <Button            android:id="@+id/button3"            android:layout_width="0dp"            android:layout_height="wrap_content"            android:layout_weight="1"            android:onClick="onBtn3Click"            android:text="Button3" />    </LinearLayout></LinearLayout>

相关文章:

http://www.cnblogs.com/answer1991/archive/2012/05/08/2489844.html

http://www.cnblogs.com/Gaojiecai/archive/2013/05/30/3107546.html

0 0
原创粉丝点击