WebView not shown inside TabHost on Honeycomb when open tab first time

对着背影说爱祢 提交于 2020-01-17 02:54:10

问题


Have the following view in my app:

<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"
    android:paddingTop="0dip">
    <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="wrap_content"
        android:padding="5dp">
        <ScrollView android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            ....first tab content....
        </ScrollView>
        <WebView android:id="@+id/description" android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:layout_weight="1">
        </WebView>
    </FrameLayout>
</LinearLayout>
</TabHost>

In activity:

TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab_details").setIndicator("Details",getResources().getDrawable(R.drawable.ic_tab_details)).setContent(R.id.details));
tabHost.addTab(tabHost.newTabSpec("tab_description").setIndicator("Description",getResources().getDrawable(R.drawable.ic_tab_description)).setContent(R.id.description));
tabHost.setCurrentTab(0);

WebView descriptionView = (WebView)findViewById(R.id.description);

String formattedDescription = converter.toHtmlPage(description);
descriptionView.loadData(formattedDescription, "text/html", "utf-8");

Everything fine for Android 1.6-2.3 But on Honeycomb (tested on Android 3.1 emulator) - when I first time open description tab - webview not shown. After return to previous tab and open again - webview shown properly.


回答1:


While I still thinking that this is Honeycomb bug (but found something similar here http://code.google.com/p/android/issues/detail?id=15399 for 2.2), I found the workaround:

Use android:layout_height="wrap_content" for webview instead of fill_parent still give me what I want and shown immediately.



来源:https://stackoverflow.com/questions/7214143/webview-not-shown-inside-tabhost-on-honeycomb-when-open-tab-first-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!