为了清楚起见,加载速度很慢,而不是动画。
我在 AsyncTask 上使用它,如下所示:
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
}
}
这里一切正常。
我对这段代码的问题是,一旦对话框出现,Lottie 动画需要一秒钟才能出现在屏幕上。如果它在 4G 网络上,我可以看到动画。如果它在 WIFI 上,我唯一能看到的就是文字。
对话框弹出后如何使动画显示出来?