1

我有一个带有 TabWidget 的 TabHost。但是我的 WebView(在每个选项卡中我都有一个 webview)在 TabWidget 上方。所以我看不到我的 TabWidget。我该如何解决?

布局文件

    <TabHost
        android:id="@+id/tabHost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_x="0sp"
        android:layout_y="0sp" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="60sp" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                  <WebView
                      android:id="@+id/webView2"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:layout_gravity="bottom"/>

                  <WebView
                      android:id="@+id/webView3"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent" 
                      android:layout_gravity="bottom" />

                  <WebView
                      android:id="@+id/webView1"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:layout_gravity="bottom"/>

             </FrameLayout>
        </RelativeLayout>
    </TabHost>
</AbsoluteLayout>

Java 公共类 MainActivity 扩展 Activity {

 /** Called when the activity is first created. */
TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tabHost=(TabHost)findViewById(R.id.tabHost);
        tabHost.setup();

        TabSpec spec1=tabHost.newTabSpec("Vandaag");
        spec1.setContent(R.id.webView1);
        spec1.setIndicator("Vandaag");


        TabSpec spec2=tabHost.newTabSpec("Morgen");
        spec2.setIndicator("Morgen");
        spec2.setContent(R.id.webView2);


        TabSpec spec3=tabHost.newTabSpec("Overmorgen");
        spec3.setContent(R.id.webView3);
        spec3.setIndicator("Overmorgen");
        tabHost.addTab(spec1);
        tabHost.addTab(spec2);
        tabHost.addTab(spec3);
        tabHost.getCurrentView().setVisibility(View.VISIBLE);
        tabHost.setup();

        WebView myWebView1 = (WebView) findViewById(R.id.webView1);
        myWebView1.setWebViewClient(new WebViewClient());
        myWebView1.loadUrl("http://www.example.com");

        WebView myWebView2 = (WebView) findViewById(R.id.webView2);
        myWebView2.setWebViewClient(new WebViewClient());
        myWebView2.loadUrl("http://www.example.com");

        WebView myWebView3 = (WebView) findViewById(R.id.webView3);
        myWebView3.setWebViewClient(new WebViewClient());
        myWebView3.loadUrl("http://www.example.com");

}
4

1 回答 1

1

RelativeLayout要么用垂直替换你的LinearLayout,要么正确使用你的RelativeLayout,给孩子们制定规则,让他们按照你想要的方式调整大小/定位。

另外,我真的不推荐硬编码的高度,就像你在WebViews.

于 2013-09-07T18:00:57.773 回答