android - 如何在android中实现双标签 Activity ?

标签 android android-tabhost

我想制作一个在一个 View 中有两次点击的 android 应用程序,即有上标签和下标签。

根据下标签的选择,我在下标签的 tapcontent 部分添加了新标签主机(用于上标签)。但是,上部的水龙头不会上升,它会粘在下部的标签上。

上层tab的实现是,

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 个水龙头应该固定在天花板上,比如,

□□□□□□□□□□□□□□□□□□□□□□□□□□
□       □        □       □
□upper1 □ upper2 □ upper3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
□                        □
□                        □
□                        □
□                        □
□                        □
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ lower1□ lower2 □ lower3□
□□□□□□□□□□□□□□□□□□□□□□□□□□

(我得到了使用 Activity 组的建议,但它不起作用。)

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());

有问题。

我能做什么:(?

最佳答案

为了实现这种需求,这里要产生多个触摸事件。您需要设计自己的控件。

示例:- 创建和线性布局放置一个标签,将另一个按钮放在它上面。现在需要第二次点击的另一个控件。所有绑定(bind)在一起可以看起来像选项卡模拟。您可以在一个选项卡中有多个触摸元素,并且可以单独触发每个触摸事件。

最好的问候 红酒

关于android - 如何在android中实现双标签 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3697879/

相关文章:

android - 如何更改选项卡指示器的颜色

java - Android 线程阻塞 UI 除非使用同步

android - fragment onListItemClick

android - Android在两个堆叠 View 旁边显示一个正方形 ImageView

android - TabSpec SetContent 到 fragment

android - 为什么父Activity的菜单在TabHost中不显示?

android - 使用 Horizo​​ntalScrollview 选项卡主机滚动并居中

Android fragment ,在 TabHost 中找不到 id 的 View

android - 双启动 - 手机上的最新 2 "original"Android 和 iPhone 版本

android - 我如何在 android studio 中创建 keystore ?