Android Studio Picasso gif loading image for placeholder -


how can display gif loading image in picasso placeholder?

i want use gif in part code

imageview = (imageview) rootview.findviewbyid(r.id.imageview); picasso.with(getactivity()).load("http://joehamirbalabadan.com/android/android/imghome/index1.png").placeholder(r.drawable.indexloading).into(imageview); imageview3 = (imageview) rootview.findviewbyid(r.id.imageview3); picasso.with(getactivity()).load("http://joehamirbalabadan.com/android/android/imghome/index3.png").placeholder(r.drawable.indexloading).into(imageview3); 

please check , improve code..

homefragment.java

package com.example.administrator.mosbeau;  import android.app.activity; import android.app.fragment; import android.app.fragmentmanager; import android.graphics.bitmap; import android.graphics.drawable.bitmapdrawable; import android.os.bundle; import android.support.annotation.nullable; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.imageview; import android.widget.progressbar;  import com.squareup.picasso.picasso;  /**  * created administrator on 9/7/2015.  */ public class homefragment extends fragment {      public static homefragment newinstance() {         homefragment fragment = new homefragment();         return fragment;     }      public homefragment () {     }      boolean internetavailable = false;     seocnd detectconnection;      imageview imageview, imageview3;      @nullable     @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.homelayout, container, false);          detectconnection = new seocnd(getactivity());         internetavailable = detectconnection.internetconnecting();         if (internetavailable) {              imageview = (imageview) rootview.findviewbyid(r.id.imageview);             picasso.with(getactivity()).load("http://joehamirbalabadan.com/android/android/imghome/index1.png").placeholder(r.drawable.indexloading).into(imageview);              imageview3 = (imageview) rootview.findviewbyid(r.id.imageview3);             picasso.with(getactivity()).load("http://joehamirbalabadan.com/android/android/imghome/index3.png").placeholder(r.drawable.indexloading).into(imageview3);           } else {             nointernetfragment fragment = new nointernetfragment();             fragmentmanager fragmentmanager = getfragmentmanager();             fragmentmanager.begintransaction()                     .replace(r.id.container, fragment)                     .commit();         }          return rootview;     }      @override     public void onattach(activity activity) {         super.onattach(activity);         ((mainactivity) activity).onsectionattached(1);     }  } 

homelayout.xml

<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="horizontal"     android:fillviewport="false"     android:background="#fffff1f1"> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent" android:layout_height="match_parent"     android:background="#fffff1f1"     android:padding="10dp">        <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/imageview"         android:src="@drawable/index1"         android:layout_alignparentend="false"         android:layout_alignparentstart="false"         android:layout_alignparenttop="false"         android:layout_alignparentleft="false"         android:layout_alignparentright="false"         android:layout_alignwithparentifmissing="false"         android:adjustviewbounds="true"         android:layout_marginbottom="10dp"         android:layout_centerhorizontal="true"         android:background="#ffffffff" />      <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/imageview2"         android:src="@drawable/index2"         android:layout_below="@+id/imageview"         android:adjustviewbounds="true"         android:layout_marginbottom="10dp" />      <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/imageview3"         android:src="@drawable/index3"         android:layout_below="@+id/imageview2"         android:layout_alignparentbottom="true"         android:adjustviewbounds="true"         android:background="#ffffffff"         android:layout_centerhorizontal="true" />  </relativelayout> </scrollview> 

from know, android doesn't have inbuilt support gif. imageview doesn't support gif default.

i suggest use glide library image loading, , caching since provides support gif. glide similar picasso, , considered better picasso. methods used similar picasso, except has asgif() method can load image imageview gif.

glide.with(context)     .load(imageurl)     .asgif()     .placeholder(r.drawable.loading_gif)     .into(imageview); 

if keen on using picasso itself, might have stackoverflow post


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -