2017-05-06 5 views
2

EDIT: Um es zu verdeutlichen, ist es langsam zu laden, nicht zu animieren.Warum ist meine Lottie Animation so langsam?

ich es auf einem AsyncTask bin mit wie folgt:

hier gut
public class GetCurrentLocation extends AsyncTask<String, Void, String>{ 

private Context mContext; 
private View view; 

public GetCurrentLocation (View view, Context mContext) { 
this.view = view; 
this.mContext = mContext; 
} 


protected void onPreExecute() { 
super.onPreExecute(); 
    //Custom Dialog 
    customDialog = new Dialog(mContext); 
    customDialog.setContentView(R.layout.dialog_custom); 
    customDialog.setTitle("Looking for address"); 

    //Custom Dialog Animation 
    LottieAnimationView animationView = (LottieAnimationView) customDialog.findViewById(R.id.animation_view); 
    animationView.setAnimation("PinJump.json"); //Lottie's premade animation 
    animationView.loop(true); 
    animationView.playAnimation(); 

    //Custom Dialog Text 
    TextView text = (TextView) customDialog.findViewById(R.id.textView); 
    text.setText(R.string.dialog_looking_for_address); 
    customDialog.show(); 
} 

protected String doInBackground(String... params) { 
//Code removed to shorten codeblock, it calls gps location here 
return null; 
} 

protected void onPostExecute(String result) { 
super.onPostExecute(result); 
customDialog.dismiss(); 
mPostSolicitationFragment.setLocalText(); //This is the method it transfer the GPS address to the view 
} 
} 

Alles funktioniert.

Mein Problem mit diesem Code ist, dass, sobald der Dialog erscheint, die Lottie Animation eine Sekunde braucht, bevor sie auf dem Bildschirm erscheint. Wenn es im 4G-Netzwerk ist, kann ich die Animation sehen. Wenn es auf WIFI ist, ist das einzige, was ich sehen kann, der Text.

Meine Frage ist, wie kann ich die Animation auftauchen, sobald der Dialog erscheint?

Antwort

1

Zuletzt gelöst, dank Gabriel Peal

Ziemlich einfach tatsächlich. Um zu machen, die Zusammensetzung zu vermeiden, wenn der Dialog nach oben zeigt, machen wir es vor der Hand in LottieComposition, wie unten dargestellt:

 LottieComposition.Factory.fromAssetFileName(mContext, "PinJump.json", new OnCompositionLoadedListener() { 
      @Override 
      public void onCompositionLoaded(LottieComposition composition) { 
       mAnimationView.loop(true); 
       mAnimationView.playAnimation(); 
       TextView text = (TextView) customDialog.findViewById(R.id.textView); 
       text.setText(R.string.dialog_looking_for_address); 
       customDialog.show(); 
      } 
     }); 

auf diese Weise, die Animation mit dem Dialog erscheinen wird.