在底部滚动Tabhost

时间:2011-02-20 23:25:41

标签: android android-layout

我使用tabhost教程开始使用Tabhost控件。

经过一些游戏之后,我想让tabhost可滚动,我想通了。

现在我想要显示屏底部的tabhost,这对我来说无效。

切换到相对布局,此处建议:iPhone-like Tabbar

我的代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="horizontal" android:isScrollContainer="true">
<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" android:layout_alignParentBottom="true">
    <RelativeLayout android:layout_height="fill_parent"
        android:layout_width="fill_parent">
        <HorizontalScrollView android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:scrollbars="none"
            android:layout_alignParentBottom="true">
            <TabWidget android:id="@android:id/tabs"
                android:layout_alignParentBottom="true" android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
        </HorizontalScrollView>
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:padding="2dp" />
    </RelativeLayout>
</TabHost>

我需要一个暗示,为什么它不起作用/如何工作。我尝试了相对布局和layout_alignParentBottom="true"现在它有几次(在Horizo​​ntalScrollView和TabWidget中)

2 个答案:

答案 0 :(得分:3)

感谢Arve带领我“自定义控件”,我找到了一个很有希望的项目:

https://github.com/honcheng/ScrollableTabHost-for-Android

我希望其他一些寻找这种tabhost的人可以使用它:)

答案 1 :(得分:1)

可以帮助您执行此操作的库: http://code.google.com/p/androidtabs/

从他们的项目描述:

  

由于Android Tab组件的限制,我创建了一个自定义TabWidget,我已经在几个不同的项目中使用它。该小部件允许我们添加自定义背景并使用自定义图标,标签可以是顶部/底部对齐。

编辑:我自己没有测试过,但看起来很有希望。