Skip to content

Instantly share code, notes, and snippets.

@wislon
Last active April 26, 2019 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wislon/a013a189dc245da2ffef to your computer and use it in GitHub Desktop.
Save wislon/a013a189dc245da2ffef to your computer and use it in GitHub Desktop.
Transparent WebView Load Animated Gif (Xamarin Android)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<WebView
android:id="@+id/webLoadingIcon"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="120dp"
android:background="#00000000"
/>
</LinearLayout>
void LoadAnimatedGif()
{
webLoadingIcon = currentView.FindViewById<WebView>(Resource.Id.webLoadingIcon);
// expects to find the 'loading_icon_small.gif' file in the 'root' of the assets folder, compiled as AndroidAsset.
webLoadingIcon.LoadUrl(string.Format("file:///android_asset/loading_icon_small.gif"));
// this makes it transparent so you can load it over a background
webLoadingIcon.SetBackgroundColor(new Color(0,0,0,0));
webLoadingIcon.SetLayerType(LayerType.Software, null);
}
@flyingxu
Copy link

it works like a magic.

@grabkipower
Copy link

Wow, pretty much like a magic. Huge thanks!

@lalitthinker
Copy link

when i check it tablet it show in half of screen

@mrizwanghuman
Copy link

I had to remove webLoadingIcon.SetLayerType(LayerType.Software, null); to play animation.

@suchithm
Copy link

Thanks! that works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment