webView android的右边距大于左边

时间:2019-01-30 06:50:13

标签: android

我是android的完全入门,我正在创建一个基于WebView的应用程序。 我已经成功创建了我的应用程序,但是在WebView应用程序中,与左侧相比,右侧有很多空白。

我希望视口位于中心,并尽可能减少空白。

我还参考了在StackOverflow上询问的以下问题 Remove Android webview margin right and left

我尝试添加以下设置:-

    webSettings.setLoadWithOverviewMode(true);

    webSettings.setUseWideViewPort(true);

但这并没有从右侧删除空白。

下面是我的网站设置

final WebSettings webSettings = webView.getSettings();
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setDomStorageEnabled(true);
    webSettings.setGeolocationEnabled(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(webSettings.LOAD_CACHE_ELSE_NETWORK);
    webSettings.setAllowUniversalAccessFromFileURLs(true);
    webSettings.setAllowFileAccessFromFileURLs(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setAllowFileAccess(true);

下面是我的Activity_main.xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent">
<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
<ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:visibility="gone"/>
<LinearLayout
    android:id="@+id/offline_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    android:visibility="gone">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3">
        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_centerInParent="true"
            android:src="@drawable/image_offline"/>
    </RelativeLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:layout_gravity="center"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:textColor="@android:color/black"
            android:textSize="@dimen/offline_message_1_text_size"
            android:text="@string/offline_message_1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:textColor="@android:color/darker_gray"
            android:textSize="@dimen/offline_message_2_text_size"
            android:text="@string/offline_message_2"/>
        <Button
            android:id="@+id/try_again_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="60dp"
            android:layout_gravity="center"
            android:text="@string/try_again"/>
    </LinearLayout>
</LinearLayout>

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_footer">
</com.google.android.gms.ads.AdView>

0 个答案:

没有答案
相关问题