【android】ActivityGroup初体验

接触android能有快一年了吧,做过的应用确是寥寥无几,只能说,这个公司管理比较混乱,要么没活可做,要么一来就来急活……

这次据说来了个大项目,让尽快完成,结果呢?

画面部分给了只有2/3不到吧(按照以往在这个公司干活的经历来说实属正常,以前我还干过两个完全没式样,没画面的活……亲娘誒,要命阿……都的自己揣摩阿……)

式样书就给了三个画面的……一共有10多个画面,还没仔细好好“揣摩”保守估计,所以,完成这三个式样书之后我就又没事做了,这也不能这么闲着,只能看看那些没给式样书的画面,有没有什么可以研究的了,于是乎,就研究起来这个了……

ActivityGroup

画面如此这般

我的第一反应就是用TabActivity,但是,TabActivity可能弄不成这个样子的,她的定制空间太小了,后来在网上百无聊赖的晃悠,突然让我发现原来还有ActivityGroup可以用……(以前真的不知道阿)

于是非常Happy的就去找ActivityGroup制作类似Tab效果的文章比如这个

http://blog.csdn.net/hellogv/archive/2010/12/06/6057174.aspx

正当我非常happy的打算crtl+c的时候问题来了,我们敬爱的美工同志,给我的tab页面的图片竟然是连在一起的……

难道他压根就想让我实现个假的tab页面,所以每个tab页的tab标题部分他都给画了一遍???

比如:

   

算了,这样也能省些事儿,就把这一块当作背景,在其上面添加了一个TextView当作捕获的焦点,然后通过onTouch事件来控制点选的是那一部分区域……就这样一个别别扭扭的自定义tab就算勉强完成了……

新手上路,代码不好,轻拍,欢迎批评指点~~~~~~

代码如下

tablayout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned
="true" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical">
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="90px" android:background="@drawable/tab01" android:paddingTop="10px" android:paddingLeft="10px" android:paddingRight="10px" >
<TextView android:text="----------" android:id="@+id/textView1" android:layout_height="match_parent" android:layout_width="190px" android:textSize="25sp" android:paddingRight="15px" android:paddingTop="10px"></TextView>
<TextView android:text="----------" android:id="@+id/textView2" android:layout_width="190px" android:layout_height="match_parent" android:textSize="25sp" android:paddingRight="15px" android:paddingTop="10px"></TextView>
<TextView android:text="----------" android:id="@+id/textView3" android:layout_width="190px" android:layout_height="match_parent" android:textSize="25sp" android:paddingRight="15px" android:paddingTop="10px"></TextView>
<TextView android:text="----------" android:id="@+id/textView4" android:layout_width="190px" android:layout_height="match_parent" android:textSize="25sp" android:paddingRight="15px" android:paddingTop="10px"></TextView>
<TextView android:text="----------" android:id="@+id/textView5" android:layout_width="190px" android:layout_height="match_parent" android:textSize="25sp" android:paddingTop="10px"></TextView>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout3" android:layout_width="match_parent" android:layout_height="50px" android:background="@drawable/title_bar">
<TextView android:text="@string/TextView14Txt" android:id="@+id/textView1" android:layout_height="match_parent" android:layout_width="match_parent" android:textSize="15sp" android:paddingRight="10px" android:paddingTop="5px" android:textColor="#ffffff"></TextView>
</LinearLayout>

<ScrollView android:id="@+id/scrollView1" android:layout_height="fill_parent" android:layout_width="match_parent" android:background="#ffffff">

</ScrollView>

</LinearLayout>

java代码

package com.esukei.activity;


import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class MainTabMenu extends ActivityGroup {
private TextView tabTitle1;
private TextView tabTitle2;
private TextView tabTitle3;
private TextView tabTitle4;
private TextView tabTitle5;

private LocalActivityManager mActivityManager = null;
private ScrollView container;
private LinearLayout tabLayout;
static final private int MENU_LIST1 = Menu.FIRST ;
static final private int MENU_LIST2 = Menu.FIRST + 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tablayout);
drawLayout();
setAction();

}
public void drawLayout(){
tabLayout
=(LinearLayout)this.findViewById(R.id.linearLayout1);
tabLayout.setBackgroundDrawable(
this.getResources().getDrawable(R.drawable.tab01));
tabTitle1
=(TextView) this.findViewById(R.id.textView1);
tabTitle2
=(TextView) this.findViewById(R.id.textView2);
tabTitle3
=(TextView) this.findViewById(R.id.textView3);
tabTitle4
=(TextView) this.findViewById(R.id.textView4);
tabTitle5
=(TextView) this.findViewById(R.id.textView5);


container
= (ScrollView) findViewById(R.id.scrollView1);

mActivityManager
= getLocalActivityManager();
container.removeAllViews();
container.addView(getLocalActivityManager().startActivity(
"Module1",
new Intent(MainTabMenu.this, StatusActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView());

}
public void setAction(){

tabTitle1.setOnTouchListener(
new OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
tabLayout.setBackgroundDrawable(MainTabMenu.
this.getResources().getDrawable(R.drawable.tab01));
container.removeAllViews();
container.addView(getLocalActivityManager().startActivity(
"Module1",
new Intent(MainTabMenu.this, StatusActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView());
}

if (event.getAction() == MotionEvent.ACTION_UP) {





}
return true;
}});
tabTitle2.setOnTouchListener(
new OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
tabLayout.setBackgroundDrawable(MainTabMenu.
this.getResources().getDrawable(R.drawable.tab02));

}

if (event.getAction() == MotionEvent.ACTION_UP) {

container.removeAllViews();
container.addView(getLocalActivityManager().startActivity(
"Module2",
new Intent(MainTabMenu.this, WatchActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView());


}
return true;
}});
tabTitle3.setOnTouchListener(
new OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
tabLayout.setBackgroundDrawable(MainTabMenu.
this.getResources().getDrawable(R.drawable.tab03));

}

if (event.getAction() == MotionEvent.ACTION_UP) {



}
return true;
}});
tabTitle4.setOnTouchListener(
new OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
tabLayout.setBackgroundDrawable(MainTabMenu.
this.getResources().getDrawable(R.drawable.tab04));

}

if (event.getAction() == MotionEvent.ACTION_UP) {



}
return true;
}});
tabTitle5.setOnTouchListener(
new OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
tabLayout.setBackgroundDrawable(MainTabMenu.
this.getResources().getDrawable(R.drawable.tab05));

}

if (event.getAction() == MotionEvent.ACTION_UP) {



}
return true;
}});

}
这个是公司的项目了,不能给出源码,只能稍微给出一些关键性的代码,然后呢就是这个东西也是相当不成熟了,还有很多东西我还没搞明白,比如说子Activity里的menu怎么调出,还有在这个ActivityGroup的基础上怎么实现子Activity怎么跳转到子Activity,这个有待研究…………

posted on 2011-04-29 13:09  曼妙琳珑心  阅读(1650)  评论(7编辑  收藏  举报

导航