Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
951 views
in Technique[技术] by (71.8m points)

android - Loading gif in WebView not adjusting to WebView

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

enter image description here

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

My html is :

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

And my WebView in xml file is

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

I'm showing this html following :

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

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".

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...