Android:WebView的位置是错误的

时间:2017-05-22 09:48:14

标签: android webview position

我有一个应该全屏显示WebView但仍有问题的应用程序:

我的屏幕底部有一个白条!当我在底部滑动webview时我可以抑制它,但我希望没有用户操作就可以。

图像: enter image description here

这是我的实例化WebView的代码:

webView.getSettings().setJavaScriptEnabled(true);
//webView.setPadding(0, 0, 0, 0);
//webView.setTop(0);
//webView.setLeft(0);
webView.setInitialScale(getScale(act));
webView.setVisibility(View.VISIBLE);
webView.loadUrl(INTERNAL_LINK);


private static int getScale(Activity act){
    double widthScreen = (double) 
    MyConnection.getClientHandler().getClientData().getiDefinitionX();

    Display display = ((WindowManager) 
    act.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth();
    Double val = new Double(width)/new Double(widthScreen);
    val = val * 100d;
    return val.intValue();
}

当我不使用 getScale 时,我的网页浏览会被缩放,即使使用webview.getSettings().setUseWideViewPort(true); webview.getSettings().setLoadWithOverviewMode(true);

我的清单:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">
    <activity android:name=".MainActivity"
        android:banner="@drawable/logo"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:logo="@drawable/logo"
        android:screenOrientation="landscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <!--<category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />-->
            <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
        </intent-filter>
    </activity>
</application>

我的onCreate:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);

我的布局:

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.myContext">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
    android:id="@+id/imageview_background"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</FrameLayout>

<FrameLayout
    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"
        android:scrollbars="none"
        android:visibility="invisible"/>
</FrameLayout>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
    android:id="@+id/textview_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="name"
    android:textColor="#FF0000"/>
</FrameLayout>

<FrameLayout
    android:layout_width="100dp"
    android:layout_height="100dp">

    <ImageView
    android:id="@+id/imageview_chargement"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</FrameLayout>

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

据我所知,您想要全屏显示您的所有内容。我不知道你是如何使用webview布局的。所以我给你所有的可能性

1st ---&gt; 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:orientation="vertical">

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none" />

 </RelativeLayout>

第二名---&gt;按活动编码

 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // remove title
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
}

<强>第三---&GT;在Manifest中声明

<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>