2015-09-30 62 views
8

PicasaのプレースホルダにGIF画像を表示するにはどうすればよいですか?私は私のコードをチェックし、改善してください。この部分のコードAndroidスタジオPicasso 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); 

をGIFを使いたい

..

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

ピカソについてはわかりません。しかし、IONライブラリにはGIFサポートが組み込まれています。 https://github.com/koush/ion

7

私の知るところでは、AndroidにはGIFの組み込みサポートがありません。したがって、ImageViewはGIFをデフォルトででサポートしていません。

GIFをサポートしているので、画像の読み込みとキャッシュにはGlide libraryを使用することをお勧めします。グライドはピカソと似ており、時にはピカソよりも優れていると考えられます。使用されるメソッドは、asGif()のメソッドをImageViewにGIFとしてロードできるという点を除いて、Picassoに似ています。

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

あなたはピカソ自身を使用して上のように注目している場合は、このstackoverflow post

+1

私は現在Glideを使用していますが、問題はloading_gifがプレースホルダーで機能していないことです.GIFをプレースホルダーに入れて読み込み画像がURLの画像より先に表示されるようにします。 – Joe

+0

Glide loading gifに関する別の問題に直面しました。 1つのフレームがなく、アニメーションが不具合になります。私はhttps://github.com/koral--/android-gif-drawableを試しました。それは私のためにはうまくいくが、ImageViewではない。 – Yazon2006

1

ピカソがimageviewsのためである、あなたはWebViewの中にあなたのGIFファイルを表示することができますが、uはそれを使用カントを検討する必要がある場合がありますピカソのwebview確かに。

関連する問題