如何将webview添加到具有更多窗口小部件的布局
问题描述:
我想将webview添加到我的layout.But该布局也有其他窗口小部件。但是,当我运行应用程序时,webview将整个屏幕和其他窗口小部件消失。这里是我的布局page.xml ....如何将webview添加到具有更多窗口小部件的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" >
<WebView android:layout_width="match_parent" android:layout_height="200dp" android:id="@+id/web"></WebView>
<View android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:layout_height="2px" android:background="#ffffff" android:layout_width="fill_parent" ></View>
<TextView android:text="Simple text view" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
,并在活动课
setContentView(R.layout.page);
WebView wv1=(WebView)findViewById(R.id.web);
wv1.loadUrl("http://google.com");
它不显示视图和TextView的,但web视图得到整个screen.Please告诉我什么我我在这里做错了什么,或者我应该做的正确方法是什么。 谢谢。
答
试着设置WebViewClient,它会解决你的问题。你这样的XML,那么你的TextView VILL将在钮所示,视图将TextView的上方显示
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView wv1=(WebView)findViewById(R.id.web1);
wv1.setWebViewClient(new myClient());
wv1.loadUrl("http://google.com");
}
class myClient extends WebViewClient
{
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
}
}
答
变化,web视图将在剩下的SPase显示。
<RelativeLayout
...
>
<TextView
android:layout_alignParentBottom="true"
android:id="@+id/sample_text"
...
/>
<View
android:layout_above="@id/sample_text"
android:id="@+id/sample_view"
...
>
<WebView
android:layout_above="@id/sample_view"
...
/>
</RelativeLayout>
在这里你可以找到答案http://stackoverflow.com/questions/3382188/how-to-set-webview-as-non-fullscreen –
感谢侯赛因,我认为重定向使问题作为CommonsWare说那里。 google.com重定向到google.lk,然后浏览器让我发疯。 – sampathpremarathna