【发布时间】:2012-07-17 15:39:05
【问题描述】:
我想创建一个具有如下 UI 的应用程序..我在屏幕中添加了两个 webview..我想当点击 webview2 时,webview1 将隐藏并且 webview2 将填充全屏...如果两个 webview 加载 url 是“ http://www.google.com" ,它将显示两个单独的 webview 但如果我加载一个不同的 URL "http://www.google.com" 作为 "http://www.youtube.com" 它只显示1 webview youtube 全屏..我必须怎么做..谢谢
这是文件 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/layout1"
android:layout_weight="1"
>
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webview1"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/layout2"
android:layout_marginLeft="10dip"
>
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webview2"
/>
</LinearLayout>
这是 Activity 中的代码:
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
height = displaymetrics.heightPixels;
width = displaymetrics.widthPixels;
layout1=(LinearLayout)findViewById(R.id.layout1);
layout2=(LinearLayout)findViewById(R.id.layout2);
webview1=(WebView)findViewById(R.id.webview1);
webview1.loadUrl("http://www.google.com");
webview2=(WebView)findViewById(R.id.webview2);
webview2.loadUrl("http://www.google.com");
final LayoutParams lp=webview1.getLayoutParams();
final LayoutParams lp1=webview2.getLayoutParams();
lp.height=height;
lp1.height=height;
webview1.setLayoutParams(lp);
webview2.setLayoutParams(lp1);
webview2.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
webview1.setVisibility(View.GONE);
lp.height=height;
lp.width=width;
webview2.setLayoutParams(lp);
}
});
【问题讨论】: