Android - Tabhost Inside ScrollView
-
26-10-2019 - |
Вопрос
Я пишу приложение, которое реализует вложенные вкладки. Потому что два набора вкладок занимают довольно много места и, как правило, потому что природа контента, который я хотел бы поместить весь внутренний табуст в прокручиваемую структуру. Я могу сделать табуляцию внешней активности Framelayout, Linearlayout, даже Viewflipper; Когда я пытаюсь сделать это 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>
Так что, очевидно, Табхост любит жить в не разбесных кадрах. Есть ли способ обойти это, не создавая много беспорядка?
Решение
Извините, я понял это самостоятельно. Решение состоит в том, чтобы обернуть второй табуст в ScrollView в своем собственном XML -файле. Это работает просто отлично.
Внешний:
<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>
Не связан с StackOverflow