簡體   English   中英

如何從webview的右邊刪除多余的空間?

[英]How to remove the extra space from right in a webview?

嗨,我正在使用此代碼進行Web視圖加載一些html數據。 它工作得非常好,但右側顯示了額外的空白。

            WebView tvone = (WebView) findViewById(R.id.web);
            tvone.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
            tvone.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            pd = ProgressDialog.show(viewdetails.this, "", "Laden", true);
            pd.setCancelable(true);
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            pd.dismiss();
        }
    });

    tvone.loadDataWithBaseURL(null, html_data, "text/html", "utf-8", null);

我使用過onTouchListener的一些技巧,可以解決問題,但鏈接不起作用。 我需要通過webview中的工作鏈接刪除空間。 請幫助我是新手。

編輯

在此處輸入圖片說明在此處輸入圖片說明

          <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:gravity="center" >

<WebView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="10dp"
            />

為了您的關心,請嘗試將WebView的寬度設置為“ fill_parent”

例如:

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

還有你的java類

public class AppWebView extends Activity{

    WebView webView;
    ProgressBar pBar;

    @SuppressLint("SetJavaScriptEnabled")
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web_view);
        pBar = (ProgressBar)findViewById(R.id.progressBar1);
        //pBar.setVisibility(View.GONE);


        String newUrl;
        if (savedInstanceState == null) {
            Bundle extras = getIntent().getExtras();
            if (extras == null) {
                newUrl = null;
            } else {
                newUrl = extras.getString("url");
            }
        } else {
            newUrl = (String) savedInstanceState
                    .getSerializable("myJsonStringS");
        }

        Log.d("jitendra", newUrl);

        //SharedPreferences sp = getSharedPreferences("booking_detail", 0);
        //String jsonString = sp.getString("jsonString", "");

        webView = (WebView)findViewById(R.id.webView1);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new myWebClient());
        webView.loadUrl(newUrl);

    }
    public void moveToThanksPage()
    {
        Intent intent = new Intent(this,ThankYou.class);
        startActivity(intent);
    }
     public class myWebClient extends WebViewClient
        {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                Log.d("sagarWeb", url);
                if (url.startsWith("mailto:")) {
                    String[] blah_email = url.split(":");
                    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                    emailIntent.setType("text/plain");
                    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{blah_email[1]});
                 //   emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "what_ever_you_want_the_subject_to)");
                    Log.d("NOTICE", "Sending Email to: " + blah_email[1] + " with subject: " + "what_ever_you_want_the_subject_to_be");
                    startActivity(emailIntent);
                }
                else if (url.startsWith("tel:")) {
                    Log.d("Web", "tell");
                    String uri = url;
                    Intent intent = new Intent(Intent.ACTION_CALL);
                    intent.setData(Uri.parse(uri));
                    startActivity(intent);
                }
                else if (url.endsWith("error.jsp")) {
                    Log.d("Web", "Error");
                }
                /*else if (url.contains("thankyou/app")) {

     //===================== USE UNDERMENTIONED COMMENT ON FOR SELF THANKS PAGE ==================//

                    //moveToThanksPage(); 
                }*/
                else
                {
                    view.loadUrl(url);
                    pBar.setVisibility(View.VISIBLE);
                }
                return true;

            }

            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                pBar.setVisibility(View.GONE);
                super.onPageFinished(view, url);

                //progressBar.setVisibility(View.GONE);
            }

        }
}

這對您有幫助。 您可以嘗試以下代碼:

 webview2.xml layout file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="55dp"
    android:orientation="vertical" >

    <WebView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webView_info"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
         >
    </WebView>
</LinearLayout>

這是您的代碼。

public class WebView2 extends Activity {

String new_url;
WebSettings webSettings;
WebView webView;

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview2);
    webView = (WebView) findViewById(R.id.webView_info);

    Bundle b = getIntent().getExtras();
    String information = b.getString("information");


    webView.setVerticalFadingEdgeEnabled(false);
    webSettings = webView.getSettings();
    //swebSettings.setDefaultZoom(ZoomDensity.FAR);
    webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    webView.getSettings().setJavaScriptEnabled(true);

    webView.setWebViewClient(new WebViewClient(){
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            Log.v("here","here");
            view.scrollBy(0, view.getContentHeight());
        }
    });     

    System.out.println("information: "+information);
    webView.loadDataWithBaseURL(null, information, "text/html", "UTF-8", null);

    webView.setWebViewClient(new VideoWebViewClient());
     webView.getSettings().setBuiltInZoomControls(true);
     webView.getSettings().setUseWideViewPort(false);
    webView.getSettings().setLoadWithOverviewMode(true);

}

@Override
public void onPause() {
    super.onPause();

}

@Override
public void onStop() {
    super.onStop();

}


 private class VideoWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            try{
                System.out.println("url called:::" + url);
                if (url.startsWith("tel:")) {
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                    startActivity(intent);
                }  else if (url.startsWith("http:")
                        || url.startsWith("https:")) {

                     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
                     startActivity(intent);

                }  else if (url.startsWith("mailto:")) {

                    MailTo mt=MailTo.parse(url);

                    //String row[] = url.split("mailto:");
                    //System.out.println("mail to: "+row[1].toString());
                    //String email_add = row[1];
                    send_email(mt.getTo());

                }
                else {
                    return false;
                }
            }catch(Exception e){
                e.printStackTrace();
            }

            return true;
        }

    }
// sending email
    public void send_email(String email_add) {
        System.out.println("Email address::::" + email_add);

        final Intent emailIntent = new Intent(
                android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                new String[] { email_add });
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
    WebView2.this.startActivity(Intent.createChooser(emailIntent,
                "Send mail..."));

    }

@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();

}

}

內容超出了寬度。 因此,這已添加到內容中。

           .div{white-space: -moz-pre-wrap !important;  /* Mozilla, since 1999 */    
                white-space: -pre-wrap;      /* Opera 4-6 */     white-space: -o-pre-wrap;                                                                                                         
                white-space: pre-wrap;       /* css-3 */     word-wrap: break-word;       /* Internet Explorer 5.5+ */    
                word-break: break-all;     
                white-space: normal;}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM