Android: WebView load image in center

Try this.

myWebView.loadData("<html><head><style type='text/css'>body{margin:auto auto;text-align:center;} img{width:100%25;} </style></head><body><img src='www.mysite.com/myimg.jpeg'/></body></html>" ,"text/html",  "UTF-8");

I did it by using some code and xml :

<WebView            android:id="@+id/webview"
                    android:layout_width="fill_parent"
                    android:layout_height="251dp"
                    android:layout_below="@+id/download"
                    android:layout_marginTop="20dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"/>

and this (for horizental center) :

WebView loading = (WebView)rootView.findViewById(R.id.webview);
                                loading.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
                                loading.loadDataWithBaseURL("file:///android_asset/", "<html><center><img src=\"done.png\"></html>", "text/html", "utf-8", "");

Or this for (horizontal & vertical center) :

WebView loading = (WebView)rootView.findViewById(R.id.webview);
                            loading.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
                            loading.loadDataWithBaseURL("file:///android_asset/", "<html>\n" +
                                    "<body bgcolor=\"white\">\n" +
                                    "    <table width=\"100%\" height=\"100%\">\n" +
                                    "        <tr>\n" +
                                    "            <td align=\"center\" valign=\"center\">\n" +
                                    "                <img src=\"loading.gif\">\n" +
                                    "            </td>\n" +
                                    "        </tr>\n" +
                                    "    </table>\n" +
                                    "</body>", "text/html", "utf-8", "");

Try something like this:

Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();

String data = "<body><center><img width=\"" + width + "\" src=\"" + url
              + "\" /></center></body></html>";
webview.loadData(data, "text/html", null);