2012-08-13 48 views
0

我有一个简单的应用程序,只需按一下按钮,当按下按钮时,对话框将打开并显示进度条。 当网址加载后,它会在网页视图中显示图片。 有趣的是,如果你按100次,它有时不会打开。 在Android 2.3.3和仿真器4.0.3上的真实设备上测试它。对话框中的Web视图有时不显示图像

有人知道为什么吗?

HelloWebViewActivity.java

public class HelloWebViewActivity extends Activity { 

ProgressBar progressBar; 
WebView a; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    this.getWindow().requestFeature(Window.FEATURE_PROGRESS); 
    setContentView(R.layout.main); 

    TextView buttona = (TextView) findViewById(R.id.button); 
    buttona.setOnClickListener(new OnClickListener() { 
    public void onClick(View v) { 
     final Dialog dialog = new Dialog(HelloWebViewActivity.this); 
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     dialog.requestWindowFeature(Window.FEATURE_PROGRESS); 
     dialog.setContentView(R.layout.webview); 

     a = (WebView) dialog.findViewById(R.id.webview); 
     a.getSettings().setSupportZoom(true);  
     a.getSettings().setBuiltInZoomControls(true); 

     progressBar = (ProgressBar) dialog.findViewById(R.id.progressbar); 
     progressBar.setProgress(0); 
     progressBar.setVisibility(View.VISIBLE); 
     a.setWebChromeClient(new WebChromeClient(){ 
     public void onProgressChanged(WebView view, int progress) { 
      progressBar.setProgress(progress); 
      if(progress == 100) { 
       progressBar.setVisibility(View.GONE); 
       } 
      } 
    }); 
     a.loadUrl("http://www.deshow.net/d/file/car/2010-10/seat-electric-car-879-2.jpg"); 
     dialog.setCancelable(true); 
     dialog.show(); 
     } 
    }); 

} 
} 

webview.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" > 


<ProgressBar 
    android:id="@+id/progressbar" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="20dp" 
    android:max="100" 
    android:visibility="gone" /> 

<WebView 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/> 

</LinearLayout> 

回答

0

我并没有解决这个问题,但是周围做了工作。 我在一个新的活动中使用onResume事件制作了webview,它检索图像的url。 通过这种方式,图像被加载到活动中而不是对话框中,看起来不那么花哨,但始终加载进度轮。

相关问题