Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package pl.droidsonroids.gif.sample;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.SpannableStringBuilder;
import android.text.style.ImageSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.IOException;
import pl.droidsonroids.gif.GifDrawable;
public class ImageSpanFragment extends Fragment implements Drawable.Callback {
private TextView tv;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
tv=new TextView(getActivity());
SpannableStringBuilder ssb=new SpannableStringBuilder("test");
GifDrawable gd = GifDrawable.createFromResource(getResources(), R.drawable.anim_flag_england);
gd.setBounds(0, 0, gifDrawable.getIntrinsicWidth(), gifDrawable.getIntrinsicHeight());
gd.setCallback(this);
ssb.setSpan(new ImageSpan(gd), 1, 2, 0);
tv.setText(ssb);
return tv;
}
@Override
public void invalidateDrawable(Drawable who) {
tv.invalidate();
}
@Override
public void scheduleDrawable(Drawable who, Runnable what, long when) {
tv.postDelayed(what, when);
}
@Override
public void unscheduleDrawable(Drawable who, Runnable what) {
tv.removeCallbacks(what);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment