2011-08-18 123 views
0

我有一个tabhost,其中包含三个制表符,并与三个活动相关联。所有三个标签都位于上方。我怎样才能使这三个标签在底部?如何在底部添加制表符

我发现这个,但仍然有一些问题。

这是我tabhost XML文件:

<?xml version="1.0" encoding="UTF-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" /> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0"/> 
    </LinearLayout> 
</TabHost> 

在我TabActivity类,我有以下代码:

setContentView(R.layout.tabs); 

TabHost mTabHost = (TabHost)findViewById(android.R.id.tabhost); 

mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class))); 
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class))); 
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class))); 

mTabHost.setCurrentTab(0); 

有一个名为TabActivity1一个活动,我也包括在清单文件。但它显示的错误:

Can't get the activity TabActivity1.

+0

您是否在Manifest文件中包含了AndroisTabViewActivity?请说明您收到了哪种错误。也许它甚至与注册清单中的活动无关。 – Kostas

+0

是的,我把它包含在清单文件中。我不知道如何让你的日志猫图片。所以我会写错误。只需等待。 –

+0

这里是我的错误:无法启动activityComponentInfo {com.mirza.tabViewDemo/com.mirza.tabViewDemo.AndroisTabViewActivity}:android.content.ActivityNotFoundException显式活动类{com.mirza.tabViewDemo/com.mirza.tabViewDemo.TabActivity1} –

回答

1

我假设你想显示 “选项卡” 窗口底部,只是试试这个:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:id="@+id/linearLayout1" 
    android:layout_height="match_parent"> 

    <TabWidget 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@android:id/tabs" 
     android:layout_alignParentBottom="true"> 
    </TabWidget> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@android:id/tabcontent"> 
    </FrameLayout> 
</RelativeLayout> 

+0

Thanks.Your code也起作用,我也是。我只是在清单文件中输入错误。我输入了活动而不是活动。让所有人参与。 :d –

0

如果您想使用LinearLayout

<?xml version="1.0" encoding="UTF-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 
</TabHost> 

有了这个解决方案,tab content将没有空间首先,TabWidget将自己的空间,那么剩下的空间将被给予tab content