【问题标题】:WebView white screenWebView 白屏
【发布时间】:2011-05-20 12:04:14
【问题描述】:

我的 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 权限

非常感谢

【问题讨论】:

  • 那个listemod布局是什么..你设计的..?

标签: android android-activity webview


【解决方案1】:

不要将 layout:height="fill_parent"webview 设置为 fillparent,而是将其设置为 layout_height="wrap_content"。因为如果您将 webview 作为填充父项,那么您将看不到 listview。我已经设置了 minimum:height 和 background color 这些不是强制性的。

别忘了给我的答案投票。如果对你有用。

谢谢

迪帕克

请找到以下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>

【讨论】:

  • 非常感谢你,我试过你的修改,它的工作!
  • 欢迎。我很乐意帮助你。祝你有美好的一天。
【解决方案2】:

不要使用fill_parent到所有Views..尝试使用权重来管理布局的比例...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 2020-07-17
    • 2013-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    相关资源
    最近更新 更多