在WebView中加载gif无法适应WebView [英] Loading gif in WebView not adjusting to WebView

查看:121
本文介绍了在WebView中加载gif无法适应WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to load a gif into WebView, it's working ok, but the problem is that I see this :

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

The problem is that I can scroll and I'm not seeing the .gif completly in the WebView.

我的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,我不希望它可以滚动,而是要显示完整的网络".

NOTE: My .gif is 330 x 750

What is my goal?

I want to see my .gif in that space on the screen and I do not want it to be scrollable I want to show the full "web".

我也尝试过Glide,但是当我将.gif放入ImageView时,它的滞后性太强了,这就是为什么我使用webView的原因.

I've tried also Glide but when I put that .gif into an ImageView it lags so hard that's why I use a webView.

推荐答案

我相信您应该尝试使用此

I believe you should try using this https://github.com/koral--/android-gif-drawable instead of wasting time play with infamous Android error-prone webview.

这篇关于在WebView中加载gif无法适应WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆