【问题标题】:How to zoom out in WebView on Android TV [SDK 22]?如何在 Android TV [SDK 22] 上缩小 WebView?
【发布时间】:2016-08-26 23:37:56
【问题描述】:

我在缩小 WebView 的内容时遇到问题,该内容对于默认比例来说太大了。

我正在为 720p Android TV 进行开发,我遵循了所有可能的建议:

    webView = (WebView) findViewById(R.id.main_wv);
    webView.setInitialScale(1);
    webView.getSettings().setUserAgentString(newUA);
    webview.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setScrollbarFadingEnabled(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setPadding(0, 0, 0, 0);

这是我当前的设置,我尝试启用其中一些而不是其他设置,但仍然没有改变。

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
android:layout_height="match_parent">

<WebView
    android:id="@+id/main_wv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"></WebView>
</android.support.v7.widget.LinearLayoutCompat>

我犯了什么错误还是某种邪恶的错误?

我只是想尽可能地缩小以适应无法完全显示的巨大图表。

EDIT1:我尝试将android.support.v7.widget.LinearLayoutCompat 更改为FrameLayout。没有任何改变。

EDIT2:我也试过webView.zoomBy(0.02f),还是不行。

【问题讨论】:

    标签: android webview android-tv


    【解决方案1】:

    您可以尝试将其添加到WebView.

    webview.getSettings().setUseWideViewPort(true);
    webview.getSettings().setLoadWithOverviewMode(true);
    

    在您的XML 中尝试使用Frame Layout

    <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            <WebView
                android:id="@+id/webView1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clickable="true"
                android:focusable="true"
                android:focusableInTouchMode="true"
                />
    
        </FrameLayout>
    

    【讨论】:

    • 我建议你把Frame Layout放在你的xml里,把Web View放在里面试试。
    • 我不确定这可能是Android TV 的邪恶错误。
    猜你喜欢
    • 1970-01-01
    • 2020-11-30
    • 2016-06-27
    • 1970-01-01
    • 1970-01-01
    • 2020-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多