Android:WebView的位置是错误的

问题描述 投票:0回答:1

我有一个应该在全屏显示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);,我的webview也会被缩放

我的清单:

<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>
android webview position
1个回答
0
投票

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

1st ---> WebView Inside Layout

<?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>

第2 --->通过编码IN活动

 @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);
}

第3 --- ---在Manifest中声明

<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
© www.soinside.com 2019 - 2024. All rights reserved.