3

enter image description here

I make gif Files animated then, I put this one in the Application's imageview.

GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(character6);
            Glide.with(this).load(R.raw.company_normal8).into(imageViewTarget);

here's code and I have no problem with apply this one.

But I have serious issue that The image have afterimage.

I made this gif file with photoshop and It have 2 frame

There's A frame and B frame.

But at android app,

A -> B -> A -> B (this is the normal one)

But My app

A -> A+B -> A -> A+b (like this afterimage)

Matthew Shearer
  • 2,715
  • 3
  • 23
  • 32
InhoLee
  • 59
  • 6

1 Answers1

3

You can use asGif

Glide.with(context)
    .load(imgUrl)
    .asGif()
    .placeholder(R.drawable.img)
    .crossFade()
    .into(imageView);

OR

Try this if Glide is not working for you,Its working for me

public class GIFView extends View{

    Movie movie;
    long moviestart;

    public GIFView(Context context) throws IOException { 
        super(context);
    }
    public GIFView(Context context, AttributeSet attrs) throws IOException{
        super(context, attrs);
    }
    public GIFView(Context context, AttributeSet attrs, int defStyle) throws IOException {
        super(context, attrs, defStyle);
    }

    public void loadGIFResource(Context context, int id)
    {
        //turn off hardware acceleration
        this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        InputStream is=context.getResources().openRawResource(id);
        movie = Movie.decodeStream(is);
    }

    public void loadGIFAsset(Context context, String filename)
    {
        InputStream is;
        try {
            is = context.getResources().getAssets().open(filename);
            movie = Movie.decodeStream(is);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (movie == null) {
            return;
        }

        long now=android.os.SystemClock.uptimeMillis();

        if (moviestart == 0) moviestart = now;

        int relTime;
        relTime = (int)((now - moviestart) % movie.duration());
        movie.setTime(relTime);
        movie.draw(canvas,10,10);
        this.invalidate();
    }
}

XML

<yourpackagename.GIFView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="50dp"
        android:layout_marginTop="110dp"
        android:src="@drawable/yourgifimage"/>

To set the image

imagevw.loadGIFResource(this, R.drawable.yourgifimage);
Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
  • I make my source like this Glide.with(this).load(R.raw.employer_normal).asGif().into(imageViewTarget); But into method have red line :( – InhoLee Jun 02 '17 at 03:48
  • I removed error But still background stacks.. I really want to remove this one – InhoLee Jun 02 '17 at 03:58
  • thank you for comment.. But if i use GIfview way, The image disappears,, – InhoLee Jun 02 '17 at 07:08
  • Fianlly I solve this problem, I have a big mistake in Gradle option. I use glide 3.5.0. The error disappears when I update to 3.8.0 – InhoLee Jun 09 '17 at 12:05