Skip to content

Instantly share code, notes, and snippets.

@citizenblr
Last active December 29, 2015 09:09
Show Gist options
  • Save citizenblr/7648327 to your computer and use it in GitHub Desktop.
Save citizenblr/7648327 to your computer and use it in GitHub Desktop.
Code snippet for "Android & how to use animated GIF" blog post - http://weavora.com/blog/2012/02/07/android-how-to-use-animated-gif/
private void setAttrs(AttributeSet attrs) {
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.GIFView, 0, 0);
String gifSource = a.getString(R.styleable.GIFView_src);
//little workaround here. Who knows better approach on how to easily get resource id - please share
String sourceName = Uri.parse(gifSource).getLastPathSegment().replace(".gif", "");
setGIFResource(getResources().getIdentifier(sourceName, "drawable", getContext().getPackageName()));
a.recycle();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment