我正在尝试将 gif 加载到 WebView
中,它工作正常,但问题是我看到了这个:
问题是我可以滚动,但在 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/