开发者

using tabs with a webview

I am trying to use tabs with a webview but I cant seem to get it to work together, i can only get one or the other to display depending on where i put the webview but not both at the same time.

here is my main.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 xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent" android:layout_width="match_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"
        android:padding="5dp" />    
    <WebView android:id="@+id/webView1" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"></WebView>    
</LinearLayout>
</TabHost>

that way only displays the tabs, if i move the webview above the tabwidget then only the webview displays. ho开发者_如何学Pythonw do i get them both to display?


I hat Problems with the TabView too, solved it by using a Tabactivity instead of TabWidget:

public class main extends TabActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    tabHost = getTabHost();
    tabHost.addTab(tabHost.newTabSpec("tab1")
            .setIndicator("", getResources().getDrawable(android.R.drawable.ic_menu_preferences))
            .setContent(new Intent(this,tab1.class)));
    tabHost.addTab(tabHost.newTabSpec("tab2")
            .setIndicator("", getResources().getDrawable(android.R.drawable.ic_menu_agenda))
            .setContent(new Intent(this,tab2.class)));
    tabHost.addTab(tabHost.newTabSpec("tab3")
            .setIndicator("", getResources().getDrawable(android.R.drawable.ic_menu_edit))
            .setContent(new Intent(this,tab3.class)));

    tabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if(tabId.equals("tab1")){

            }else if(tabId.equals("tab2")){

            }else if(tabId.equals("tab3")){

            }
        }   
    });
}}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜