android - 在 WebView 中加载 gif 不适应 WebView

标签 android android-layout webview

我正在尝试将 gif 加载到 WebView 中,它工作正常,但问题是我看到了这个:

enter image description here

问题是我可以滚动,但在 WebView 中看不到完整的 .gif。

我的 html 是:

<html style="margin: 0;">
<body style="margin: 0;">
<img src="tuto1.gif" style="width: 40%; height: 70%" />
</body>
</html>

而我在 xml 文件中的 WebView

<FrameLayout 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"
    android:padding="@dimen/activity_horizontal_margin">


    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <WebView
            android:id="@+id/webViewPager"
            android:layout_width="@dimen/_200sdp"
            android:layout_height="@dimen/_250sdp"
            android:layout_gravity="center"
            android:adjustViewBounds="true"
            android:scaleType="fitCenter" />
    </FrameLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:gravity="center"
        android:orientation="vertical"
        android:padding="@dimen/activity_horizontal_margin">

        <TextView
            android:id="@+id/section_label"
            style="@style/TextAppearance.AppCompat.Headline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/white"
            tools:text="Page One" />

        <TextView
            style="@style/TextAppearance.AppCompat.Body1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_horizontal_margin"
            android:id="@+id/tv_description"
            android:alpha="0.7"
            android:gravity="center"
            android:textColor="@android:color/white" />
    </LinearLayout>

</FrameLayout>

我正在显示以下 html:

WebView wv = rootView.findViewById(R.id.webViewPager);
wv.loadUrl("file:///android_asset/tuto1.html");
wv.setBackgroundColor(Color.TRANSPARENT);

注意:我的 .gif 是 330 x 750

我的目标是什么?

我想在屏幕上的那个空间看到我的 .gif,我不希望它是可滚动的我想显示完整的“网络”。

我也尝试过 Glide 但是当我将那个 .gif 放入 ImageView 时它非常滞后,这就是我使用 webView 的原因.

最佳答案

我相信你应该尝试使用这个 https://github.com/koral--/android-gif-drawable而不是浪费时间玩臭名昭著的 Android 容易出错的 webview。

关于android - 在 WebView 中加载 gif 不适应 WebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49098464/

相关文章:

android - 如何在 Android 中为不同的分辨率使用不同的背景图片?

android - SimpleCursorAdapter 将所有内容绑定(bind)两次

android - Meta width=device-width 无法按预期在 Galaxy Nexus 上运行

android - AdMob:在WebView中显示广告

Android Studio 3.1.3,设计 View 总是空的

c# - 如何在WebView2控件上创建按钮?

android - 使用 Kotlin 在 fragment 中引用 RecyclerView 时出现空指针错误

java - 使用 Volley 的 JSON 请求

java - 私有(private)字符串还是公共(public)静态字符串?

android - 使用 HttpURLConnection 的 Android Jelly Bean 4.1 上的 HTTP 基本身份验证问题