WebView白屏
我的 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 权限
非常感谢
I have a problem with my WebView and I don't know how fix it. Before added the WebView, I had a ListView, now I have only a white screen when I launch the activity. Can you help me to fix it please ?
Here the XML file :
<?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>
And my Java file :
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");
}
}
});
}}
Note : in my manifest I have Internet permissions
Thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要将layout:height =“fill_parent”webview设置为fillparent,而是将其设置为layout_height =“wrap_content”。因为如果你将 webview 作为填充父级,那么你就看不到 listview。我设置了最小值:高度和背景颜色,这些不是强制性的。
不要忘记为我的答案投票。如果对你有用的话。
谢谢
Deepak
请找到以下 xml
Instead of setting layout:height="fill_parent"webview as fillparent make it as layout_height="wrap_content". Because if you do webview as fill parent then you cannot see listview. I have set minimum:height and background color those are not mandatory.
Donot forget to vote my answer. If it is useful for you.
Thanks
Deepak
Please find the following xml
不要对所有
View
使用fill_parent
。尝试使用权重来管理布局的比例...Don't use
fill_parent
to allView
s.. Try using weight instead to manage the proportion of the layout...