我有一个带有 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 公共(public)类 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");
}
最佳答案
用垂直的 LinearLayout
替换你的 RelativeLayout
,或者正确地使用你的 RelativeLayout
,给子元素设置规则以调整它们的大小/以您想要的方式定位。
此外,我真的不推荐硬编码高度,就像您在WebViews
上那样。
关于android - 使用 tabhost 时 WebView 无法正确填充屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18676270/