2

I am displaying some images in my webview with the help of their urls and i want them to be in center of the available space but images are being aligned at top and one more thing i am creating the webview dynamically to display in viewpager.Actually i am trying to implement functionality which should be like currently available in facebook application for android devices.

thanks.

Akram
  • 7,548
  • 8
  • 45
  • 72

2 Answers2

5

You ought to be able to wrap the images in html and center them via css. Done it in one of my apps.

public class YourActivity extends Activity {

private static final String HTML_FORMAT = "<html><body style=\"text-align: center; background-color: black; vertical-align: center;\"><img src = \"%s\" /></body></html>";
private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    mWebView = (WebView) findViewById(R.id.yourWebView);

    final String imgUrl = "http://db.tt/2283dXLT";
    final String html = String.format(HTML_FORMAT, imgUrl);

    mWebView.loadDataWithBaseURL("", html, "text/html", "UTF-8", "");
    }
}

Hope this helps

You should be able to display any number of images just by changing the imgUrl.

bytebender
  • 7,371
  • 2
  • 31
  • 54
0

I tried with your code and find solution. In additon to above code you need to put the below code in onCreate().

mWebView.getSettings().setUseWideViewPort(false); 
mH16
  • 2,356
  • 4
  • 25
  • 35