Jithu P.S
Jithu P.S

Reputation: 1843

How to fit the images in webview from url

Now i am working on a list view with webview.in this listview webview is using for showing images.and it is from the url.now i am facing a problem that from url i am not getting the unique dimension images,some images are small and some are large,while showing this tho webview it not properly arranged.how can i properly arrange/fit the webview images.i am using the following code.

<WebView
        android:layout_marginTop="5dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:id="@+id/webView"
         android:layout_width="55dp"
        android:layout_height="55dp" 

     >

code

WebView  webView = (WebView)view.findViewById(R.id.webView);
showImageOnWebView(webView, item.thumbimage,80,80);

Upvotes: 1

Views: 1279

Answers (1)

jithu
jithu

Reputation: 706

Try this code .

  String r="<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0,target-densityDpi=device-dpi\">"; 

                       String s="<html><body style=\"margin: 0; padding: 0\"><IMG  width=\"100%\" height=\"100%\" src=\""+item.image+"\"><body><html>"; 


       webView.setBackgroundColor(0); 
       webView.setBackgroundResource(R.drawable.android); 
       webView.loadData(s, "text/html","UTF-8");  

Upvotes: 1

Related Questions