2016-04-03 9 views
0

Ich versuche, eine Platzhalteranimation mit Picasso zu implementieren, die eine benutzerdefinierte Animation beim Laden aus dem Web animieren. Ich habe nach vielen Lösungen gesucht und finde keine Möglichkeit, die Animation zu verkleinern und zu zentrieren. Das Ergebnis ist, dass die Animation manchmal gestreckt, zentriert oder in einer Ecke wiedergegeben wird.Picasso Platzhalter skalieren und auf den mittleren Bildschirm passen

Die Animationsbilder sind deutlich kleiner als die Bildansicht und die heruntergeladenen Bilder. Hier

ist der Code, den ich bin derzeit mit:

Picasso.with(getActivity()).load(imageUri).fit()//.placeholder(R.drawable.progress_animation) 
       .placeholder(R.drawable.progress_animation) 
         .into(mIconView); 

Hier ist die Animation Definition:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 

android: id = "@ + id/selected" android: oneshot = "false „>

<item android:drawable="@drawable/wheel1" android:duration="50" /> 
<item android:drawable="@drawable/wheel2" android:duration="50" /> 
<item android:drawable="@drawable/wheel3" android:duration="50" /> 
<item android:drawable="@drawable/wheel4" android:duration="50" /> 
<item android:drawable="@drawable/wheel5" android:duration="50" /> 

Irgendwelche Vorschläge, wie Sie die Animationsskala und -position in Picasso steuern können, ich konnte keine Methode finden, um fit() oder resize() zu verwenden, da sie nur das endgültige Bild und nicht den Platzhalter beeinflusst und versucht, zwei davon zu verwenden Sie erzeugen eine Kollision.

+0

Gesicht gleichen Ausgabe [Re Sizing Picasso Bild] folgt aussehen (https://futurestud.io/blog/ picasso-image-resizing-scaling-and-fit) – Kathi

Antwort

1

Ich finde einen Weg mit Fortschrittsbalken und Rückruf.

mProgressView.setVisibility(View.VISIBLE); 
      Picasso.with(getActivity()).load(f).fit() 

        .into(mIcon,new Callback() { 
         @Override 
         public void onSuccess() { 
          mProgressView.setVisibility(View.GONE); 
         } 

         @Override 
         public void onError() { 
          // TODO Auto-generated method stub 

         } 
        }); 

hier ist der Layoutbereich

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="200dp" 

> 
<ImageButton 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:id="@+id/ib_place_dialog_image" 
    android:maxHeight="200dp" 
    android:layout_gravity="center_horizontal" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 
<ProgressBar 
    style="?android:attr/progressBarStyleLarge" 
    android:scaleX="0.4" 
    android:scaleY="0.4" 
    android:layout_width="128dp" 
    android:layout_height="128dp" 
    android:id="@+id/cliff_image_progress_bar" 

    android:indeterminateDrawable="@drawable/progress_animation" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" /> 

und die Animation

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/selected" android:oneshot="false"> 

    <item android:drawable="@drawable/frame_0" android:duration="30" /> 
    <item android:drawable="@drawable/frame_0" android:duration="30" /> 
<item android:drawable="@drawable/frame_0" android:duration="30" /> 
<item android:drawable="@drawable/frame_1" android:duration="30" /> 
<item android:drawable="@drawable/frame_2" android:duration="30" /> 
<item android:drawable="@drawable/frame_3" android:duration="30" /> 
<item android:drawable="@drawable/frame_4" android:duration="30" /> 
<item android:drawable="@drawable/frame_5" android:duration="30" /> 
<item android:drawable="@drawable/frame_6" android:duration="30" /> 
<item android:drawable="@drawable/frame_7" android:duration="30" /> 
<item android:drawable="@drawable/frame_8" android:duration="30" /> 
<item android:drawable="@drawable/frame_9" android:duration="30" /> 
<item android:drawable="@drawable/frame_10" android:duration="30" /> 
<item android:drawable="@drawable/frame_11" android:duration="30" /> 
<item android:drawable="@drawable/frame_12" android:duration="30" /> 
<item android:drawable="@drawable/frame_13" android:duration="30" /> 
<item android:drawable="@drawable/frame_14" android:duration="30" /> 
<item android:drawable="@drawable/frame_15" android:duration="30" /> 
<item android:drawable="@drawable/frame_16" android:duration="30" /> 
<item android:drawable="@drawable/frame_17" android:duration="30" /> 
<item android:drawable="@drawable/frame_18" android:duration="30" /> 
<item android:drawable="@drawable/frame_19" android:duration="30" /> 
<item android:drawable="@drawable/frame_20" android:duration="30" /> 
<item android:drawable="@drawable/frame_21" android:duration="30" /> 
<item android:drawable="@drawable/frame_22" android:duration="30" /> 
<item android:drawable="@drawable/frame_23" android:duration="30" /> 
<item android:drawable="@drawable/frame_24" android:duration="30" /> 
<item android:drawable="@drawable/frame_25" android:duration="30" /> 
<item android:drawable="@drawable/frame_26" android:duration="30" /> 
<item android:drawable="@drawable/frame_27" android:duration="30" /> 
<item android:drawable="@drawable/frame_28" android:duration="30" /> 
<item android:drawable="@drawable/frame_29" android:duration="30" /> 



</animation-list> 
+0

Danke, der Rückruf war wirklich nützlich. – JCarlos

Verwandte Themen