如何在android中实现双选项卡活动?
问题描述:
我想制作一个Android应用程序,它在一个视图中有两个敲击,即具有较高的选项卡和较低的选项卡。如何在android中实现双选项卡活动?
根据下标签的选择,我在下标签的tapcontent部分添加新标签主机(对于上标签)。但是,上水龙头不会上升,它会粘到较低的选项卡上。
上接片的实施是,
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class uppertab extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.upperlayout);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, recommend_friend_simillar.class);
spec = tabHost.newTabSpec("upper1").setIndicator("Upper1").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, recommend_friend_new.class);
spec = tabHost.newTabSpec("upper2").setIndicator("Upper2").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, recommend_friend_favorite.class);
spec = tabHost.newTabSpec("upper3").setIndicator("Upper3").setContent(intent);
tabHost.addTab(spec);
}
}
XML为上抽头,
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/uppertabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@+id/uppertabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/uppertabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
XML对于较低标签是,
<?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="fill_parent"
>
<TabHost android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_above="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</FrameLayout>
</RelativeLayout>
</TabHost>
</LinearLayout>
结果如下所示。
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □
□ □
□ □
□ □
□ □
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □ □ □
□upper1 □ upper2 □ upper3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ lower1□lower2 □ lower3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
当然,上3个水龙头应坚持ceilling一样,
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □ □ □
□upper1 □ upper2 □ upper3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □
□ □
□ □
□ □
□ □
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ lower1□ lower2 □ lower3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
(我在使用的ActivityGroup得到了一个建议,但它不工作。)
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class uppertab extends ActivityGroup {
private TabHost tabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.upperlay);
tabHost = (TabHost)findViewById(R.id.friendtabhost);
tabHost.setup(getLocalActivityManager());
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(new Intent(this, tab1.class)));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("tab2").setContent(new Intent(this, tab2.class)));
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab3").setContent(new Intent(this, tab3.class)));
}
}
DDMS说
tabHost.setup(getLocalActivityManager());
有问题。 ?
我能做些什么:(
答
为了达到这种要求,其中要产生多点触摸事件你需要设计自己的控制
举例: - 创建和线性布局放置一个标签,在另一个标签上放置另一个按钮,现在另一个需要第二次点击的控件,所有绑定在一起的标签可以看起来像标签模拟,你可以在一个标签中有多个触摸元素,你可以得到每个触摸事件单独触发
最好的问候 Vinod
你可能想调用你的问题“如何在android中实现**嵌套** TabActivity?”。 (还要注意'TabActivity'的拼写。) – user634618 2011-03-02 01:32:00