Simplest library for displaying animated GIF and Images on same ImageView Library has been implemented to be the simplest yet strongest of options available out there... You can display animated gifs with various configurations and also display Image view with all possible default support of Android for ImageView using a single View Component.
Implementation AnimatedGifImageView is the View class that is derived from ImageView. Therefore along with supporting all features for ImageView it also supports AnimatedGifs.
Library provides overloaded methods for setting your GIF you can use setAnimatedGif(String filePath, TYPE streachType) or setAnimatedGif(int rawResourceId, TYPE streachType) or setAnimatedGif(byte[] byteArray, TYPE streachType) depending on your requirements.
Checkout the sample for more details.
A Sample Implementation of Usage for AnimatedGifImageView
public class MainActivity extends FragmentActivity implements OnClickListener {
private AnimatedGifImageView animatedGifImageView;
boolean switchMe = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gif_main);
animatedGifImageView = ((AnimatedGifImageView)findViewById(R.id.animatedGifImageView));
animatedGifImageView.setAnimatedGif(R.raw.animated_gif,
TYPE.FIT_CENTER);
((Button) findViewById(R.id.button1)).setOnClickListener(this);
switchMe = true;
}
@Override
public void onClick(View v) {
if (!switchMe)
animatedGifImageView.setAnimatedGif(R.raw.animated_gif_big,
TYPE.STREACH_TO_FIT);
else
animatedGifImageView.setImageResource(R.drawable.ic_launcher);
switchMe = !switchMe;
}
}
SAMPLE XML
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<com.abhi.gif.lib.AnimatedGifImageView
android:id="@+id/animatedGifImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_above="@+id/button1"
android:layout_below="@+id/textView1" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Switch" />
Description Application will use setAnimatedGif(R.raw.animated_gif,TYPE.FIT_CENTER) to set an animated GIF, on press of button will set a normal image from drawables using setImageResource and again on next press of button will set Animated GIF after streaching it to full layout area by setAnimatedGif(R.raw.animated_gif_big,TYPE.STREACH_TO_FIT)
NOTE Animated images are placed in raw folder and drawable contains PNG/JPG