gpt4 book ai didi

java - 具有水平滚动问题的 TabHost

转载 作者:行者123 更新时间:2023-11-30 09:23:05 26 4
gpt4 key购买 nike

我想要不同数量的选项卡并且我正在使用 TabHost。这些可能在 1 到 8 之间,具体取决于数据。

我想添加水平滚动条,这样当所有 8 个滚动条都在那里时,它看起来就不会显得局促。

问题是当有 5 个或更多时,它看起来很好并且滚动有效!但是当标签数量较少时,我会看到空白。标签不会被拉伸(stretch)以填充额外的空间。

我该如何解决这个问题?这可以通过 Java 代码完成吗?

这是我的布局 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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<!---Other Views--->

<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<TabWidget
android:id="@android:id/tabs"
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="wrap_content" />
</LinearLayout>

</TabHost>

最佳答案

这对我有用。请尝试。

<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">

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

<TabWidget
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tabStripEnabled="true"
android:orientation="horizontal" />

</HorizontalScrollView>

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0"/>

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>

</LinearLayout>

</TabHost>

顺便说一句,它在哪里说 TabHost 已被弃用?我没有收到任何警告...还有就是靠这个post , 我相信 TabHost 还活着。

关于java - 具有水平滚动问题的 TabHost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16233914/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com