2015-09-30 16 views
8

के लिए एंड्रॉइड स्टूडियो पिकासो gif लोडिंग छवि मेरे पिकासो प्लेसहोल्डर में gif लोडिंग छवि को कैसे प्रदर्शित कर सकता हूं?प्लेसहोल्डर

मैं इस हिस्से में gif उपयोग करने के लिए कोड चाहते

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); 

कृपया जांच करें और मेरा कोड में सुधार ..

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 by 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> 

उत्तर

0

मुझे पिकासो के बारे में निश्चित नहीं है। लेकिन आईओएन लाइब्रेरी में अंतर्निहित जीआईएफ समर्थन है। https://github.com/koush/ion

7

मुझे पता है कि एंड्रॉइड के पास जीआईएफ के लिए अंतर्निहित समर्थन नहीं है। तो ImageView डिफ़ॉल्ट रूप से GIF का समर्थन नहीं करता

मैं आपको छवि लोडिंग के लिए Glide library का उपयोग करने का सुझाव दूंगा, और कैशिंग क्योंकि यह जीआईएफ के लिए समर्थन प्रदान करता है। ग्लाइड पिकासो के समान है, और कभी-कभी पिकासो से बेहतर माना जाता है। उपयोग की जाने वाली विधियां पिकासो के समान भी हैं, सिवाय इसके कि इसमें asGif() विधि है जो छवि दृश्य में जीआईएफ के रूप में छवि लोड कर सकती है।

Glide.with(context) 
    .load(imageUrl) 
    .asGif() 
    .placeholder(R.drawable.loading_gif) 
    .into(imageView); 

आप पिकासो ही प्रयोग पर इतना चाहते हैं, तो आप इस पर गौर करने के लिए हो सकता है इस stackoverflow post

+1

अब मैं ग्लाइड का उपयोग करता हूं लेकिन समस्या लोड हो रही है_जीआईफ़ प्लेसहोल्डर में काम नहीं कर रहा है .. मुझे प्लेसहोल्डर में जीआईएफ चाहिए ताकि लोडिंग छवि यूआरएल में छवि से पहले दिखाएगी .. – Joe

+0

मुझे ग्लाइड लोडिंग gif के साथ एक और समस्या का सामना करना पड़ा। एक फ्रेम अनुपस्थित और एनीमेशन glitches है। मैंने https://github.com/koral--/android-gif- हटाने योग्य कोशिश की। और यह मेरे लिए अच्छा काम करता है, लेकिन यह ImageView नहीं है। – Yazon2006

1

Picaso, imageviews के लिए है आप वेब दृश्य में अपने GIF फ़ाइल को दिखा सकते हैं, लेकिन यू नहीं कर सकते उपयोग कि निश्चित रूप से पिकासो में वेबव्यू।

संबंधित मुद्दे