Recently, I’ve worked displaying Animated Gif Image as while loading some network stuff in app screen.
Solution for displaying the Animated gif image
After some struggle for it, I finally happen to use Webview for displaying the Animated gif image which worked as required.
Here is simple code snippet
I place this WebView in a RelativeLayout
<WebView android:id=”@+id/webviewSpinner”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:layout_centerInParent=”true”
android:layout_gravity=”center”
android:scrollbars=”none”
android:visibility=”invisible” >
</WebView>
and in Activity, written following code
<!-- wp:preformatted -->
<pre class="wp-block-preformatted"><span style="font-size: 12pt;">webviewSpinner=(WebView) findViewById(R.id.webviewSpinner);
webviewSpinner.setWebViewClient(new MyWebViewClient());
webviewSpinner.getSettings().setJavaScriptEnabled(true);
webviewSpinner.setBackgroundColor(0x50000000);
webviewSpinner.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
webviewSpinner.getSettings().setRenderPriority(RenderPriority.HIGH);
webviewSpinner.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webviewSpinner.loadDataWithBaseURL(“file:///android_asset/”,htmlString,”text/html”,”utf-8”,”“);
</span></pre>
<!-- /wp:preformatted -->
and in the jave code WebView object loadDataWithBaseURL method, i place htmlString variable, which is a String variable with Html content as below
private String htmlString=”<html><body><table width="100%" height="100%"><tr><td align="center" valign="center"><img src="478_spinner.gif"></td></tr></table></body></html>”;
I just make the WebView visible and invisible while loading data, which worked like a loader.
Hope it helps somebody…
You may be also interested in