我的WebView出了点问题,我不知道怎么解决它。在添加WebView之前,我有一个ListView,现在当我启动activity时,我只有一个白屏。你能帮我修一下吗?
下面是XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ListView
android:id="@+id/lvMods"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>和我的Java文件:
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class Mods extends Test {
private ListView lvMods;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listemods);
lvMods = (ListView)findViewById(R.id.lvMods);
String[] listeStrings = {"1","2","3","4"};
lvMods.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,listeStrings));
lvMods.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
CallFunc(position);
}
private void CallFunc(int position) {
WebView wvpdf = (WebView)findViewById(R.id.webview);
wvpdf.getSettings().setJavaScriptEnabled(true);
switch (position) {
case 0:
wvpdf.loadUrl("http://docs.google.com/gview?embedded=true&url=XXXXXXXXXXXXXXXXXXXXXXXXXX");
break;
case 1 :
wvpdf.loadUrl("http://docs.google.com/gview?embedded=true&url=XXXXXXXXXXXXXXXXXXXXXXX");
break;
case 2 :
wvpdf.loadUrl("http://docs.google.com/gview?embedded=true&url=XXXXXXXXXXXXXXXXXXX");
break;
case 3 :
wvpdf.loadUrl("http://docs.google.com/gview?embedded=true&url=XXXXXXXXXXXXXXX");
}
}
});
}}注意:在我的清单中,我拥有Internet权限
非常感谢
发布于 2011-05-20 20:18:18
将layout:height="fill_parent"webview设置为layout_height="wrap_content“,而不是将其设置为填充父级。因为如果您将webview作为填充父级,那么您将无法看到listview。我已经设置了最小值:高度和背景颜色,这些都不是强制性的。
别忘了投票给我的答案。如果对你有用的话。
谢谢
深度
请查找以下xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:minHeight="60dip"
/>
<ListView
android:id="@+id/lvMods"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
</ListView>
</LinearLayout>发布于 2011-05-20 20:33:56
不要对所有的View都使用fill_parent。尝试使用权重来管理布局的比例...
https://stackoverflow.com/questions/6071624
复制相似问题