0

I am trying to place image from the html page of the rss feed to a web view.

When I Load the image, it gets zoomed in and displays only a partial image. It happens for some images randomly all the time.

But when I try to load them in simulator or after debugging , it displays all the images correctly(they fit in the web view).

How do I fix it.

Layout:

<com.philly.prosportsframework.view.ProgressWebView 
        android:id="@+id/photo" 
        android:layout_width="300dip" 
        android:layout_height="300dip"
        android:layout_below="@+id/divider"
        android:layout_centerHorizontal="true"      
        android:layout_marginTop="10dip"
        android:layout_marginBottom="10dip"/>

Piece of WebviewCode:

    int imageScale = 100;
    viewHolder.mPhoto.getSettings().setJavaScriptEnabled(true);
    viewHolder.mPhoto.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
    viewHolder.mPhoto.setBackgroundColor(Color.parseColor("#00000000"));
    viewHolder.mPhoto.setInitialScale(imageScale);  
Sweety Bertilla
  • 972
  • 10
  • 35

1 Answers1

0

The below answer helped me to fix the issue:

"String data="<html><head><title>Example</title><meta name=\"viewport\"\"content=\"width="+width+", initial-scale=0.65 \" /></head>";
data=data+"<body><center><img width=\""+width+"\" src=\""+url+"\" /></center></body></html>";
webView.loadData(data, "text/html", null);"

I set the width to 300 to fit my layout.

Its in the link: Android WebView, Scaling Image to fit the screen

Community
  • 1
  • 1
Sweety Bertilla
  • 972
  • 10
  • 35