PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 18, 2022

[FIXED] How to make gif images to fit WebView on Android

 July 18, 2022     android, gif, image, webview     No comments   

Issue

I'm using webview to display gif images, but the problem is, the webview windows doesn't fit the width of gif, there's always some blank space to the right of the gif.

Right now I have to manually set the width and try to keep the width of my gifs, but it's strange that the height always fit the gifs

        int w = 115;//image.getWidth();
        LayoutParams lp = holder.wv.getLayoutParams();    
        lp.width= (int) (w * context.getResources().getDisplayMetrics().density);
        holder.wv.setLayoutParams(lp); 

        holder.wv.loadUrl("file:///android_asset/" + text.substring(1, text.length()-1) + ".gif");
        holder.wv.setVisibility(View.VISIBLE);

Webview in xml layout

   <WebView
      android:id="@+id/wv"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" 
      android:layout_margin="2sp"
      android:gravity="center_vertical|center_horizontal"
      android:visibility="gone"/>

There is nothing wrong with the gifs, they don't have the trailing white space

Here is what it looks like on the device

enter image description here

here is the original gif

enter image description here


Solution

I had to manually edit the gif sizes so it fits the window, not a smart way to do but it was the only solution



Answered By - Casper
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing