2016-11-02 7 views
-1

내 안드로이드 응용 프로그램에 웹 브라우저없이 웹 URL을로드하고 있습니다. 그래서, 창 전체 화면에 맞게 웹보기를 만들려고하는데 작동하지 않습니다. 난 너비와 높이 fill_parent로 webview 설정했지만 여전히 작동하지 않습니다. 와 같이webview를 전체 화면으로 만들려고 시도합니다.

final ProgressBar Pbar; 
     //final TextView txtview = (TextView)findViewById(R.id.tV1); 
     Pbar = (ProgressBar) findViewById(R.id.prog1); 

     getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); 

     mWebView = (WebView) findViewById(R.id.webview); 
     mWebView.getSettings().setLoadWithOverviewMode(true); 
     mWebView.getSettings().setUseWideViewPort(true); 
     WebSettings webSettings = mWebView.getSettings(); 
     webSettings.setJavaScriptEnabled(true); 
     mWebView.loadUrl("http://unitytimes.com"); 
     mWebView.setWebViewClient(new WebViewClient() { 
      public boolean shouldOverrideUrlLoading(WebView view, String url) { 
       view.loadUrl(url); 
       return true; 
      } 
     }); 

     mWebView.setWebChromeClient(new WebChromeClient() { 
      public void onProgressChanged(WebView view, int progress) { 
       if (progress < 100 && Pbar.getVisibility() == ProgressBar.GONE) { 
        Pbar.setVisibility(ProgressBar.VISIBLE); 
        //txtview.setVisibility(View.VISIBLE); 
       } 
       Pbar.setProgress(progress); 
       if (progress == 100) { 
        Pbar.setVisibility(ProgressBar.GONE); 
        //txtview.setVisibility(View.GONE); 
       } 
      } 
     }); 

가 어떻게

+1

webview의 상위 레이아웃 코드는 무엇입니까? –

+0

전체 XML 파일을 표시했습니다. 내가 잘못하지 않으면 부모 레이아웃이 없습니다 – Francis

+0

"하지만 작동하지 않습니다"무슨 뜻입니까? – njzk2

답변

1

당신이 필요로하는 윈도우의 전체 화면을 적용하려면 웹보기를 할 수 있습니다하십시오 : 내 활동 클래스의 다음

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 


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

    <ProgressBar 
     android:id="@+id/prog1" 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:padding="2dip" /> 

</RelativeLayout> 

나는 같이이 코드를 이 모든 것을 제거하기 위해

android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 

padding은 경계와 이보기의 내용은 여기에서 콘텐츠가 webview이고 경계가 최적 실습을위한 레이아웃입니다. fill_parent 대신 match_parent을 사용해야합니다.

관련 문제