2012-06-04 28 views
1

我有这个简单的布局,我发现作为一个例子:Android 2.3.3,使得标签列表可滚动?

<?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:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <HorizontalScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:fillViewport="true" 
      android:scrollbars="none" > 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center" /> 
     </HorizontalScrollView> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 
     </FrameLayout> 
    </LinearLayout> 

</TabHost> 

在代码中加入8个选项卡后,我可以看到他们得到挤在一起。 如何将可滚动功能添加到选项卡? (只是标签,而不是内容)

我的手机上的一个应用程序有这个,这也没有任何滚动条。基本上,要移动我只需按下并按住,然后将标签拖动到左侧以显示更多标签。这怎么能实现?

回答

0

你试过吗?

<HorizontalScrollView 
    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" > 
    </TabHost> 

</HorizontalScrollView> 
+0

这也给了没有效果。使用之前的评论更新我的帖子。整个xml文件就是这个TabHost。 (这是主窗口) – Patrick

0

请尝试一下本作的TabWidget:

<HorizontalScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true" 
    android:scrollbars="none" 
    android:layout_alignParentBottom="true"> 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center"/> 
    </HorizontalScrollView> 
+0

尝试过但它不起作用。这个应用程序创建业务有点新。 Eclipse告诉我,Horizo​​ntalScrollView-> layout_alignParentBottom =“true”=“无效的布局参数在一个LinearLayout:layout_alignParentBottom”和TabWidget-> layout_width =“fill_parent”=“这个TabWidget应该使用android:layout_width =”wrap_content“任何想法?我的代码与您的代码上面) – Patrick

0

你可以尝试设置每个标签的最小宽度像这样:

for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) { 
     tabHost.getTabWidget().getChildAt(i).setMinimumWidth(200); 
    }