gpt4 book ai didi

Android - ScrollView 内的 TabHost

转载 作者:搜寻专家 更新时间:2023-11-01 09:15:49 24 4
gpt4 key购买 nike

我正在编写一个实现嵌套选项卡的应用程序。因为两组选项卡占用了相当多的空间,而且通常因为内容的性质,我想将整个内部 TabHost 放入一个可滚动的结构中。我可以制作外部 Activity FrameLayout、LinearLayout 甚至 ViewFlipper 的 tabcontent;当我尝试使其成为 ScrollView 时,程序崩溃了。

<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">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ScrollView
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>

</TabHost>

显然 TabHost 喜欢住在不可滚动的框架内。有没有什么办法可以解决这个问题而不造成一大堆困惑?

最佳答案

对不起,我自己想通了。解决方案是将第二个 TabHost 包装在它自己的 XML 文件中的 ScrollView 中。效果很好。

外部:

<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">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>

</TabHost>

内部:

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

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ViewFlipper
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>

</TabHost>

</ScrollView>

关于Android - ScrollView 内的 TabHost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4819713/

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