I have a cutstom DialogFragment
to show a loading message to the user. For the loading message image, I created an animation that goes from the left part of the screen (starting from outside the screen) to the right of the screen (finishing outside the screen). To do so, I thought of starting the animation on y=-imageWith
and finish in y=imageWith+dialogWith
:
public class MensajeDialogFragment extends DialogFragment {
TextView mTvMensaje;
TextView mTvTitulo;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
ImageView loadingImage = (ImageView) dialogView.findViewById(R.id.ivBus);
View dialogView = inflater.inflate(R.layout.layout_mensaje_dialog, null);
TextView mTvTitulo = (TextView) dialogView.findViewById(R.id.tvTitulo);
TextView mTvMensaje = (TextView) dialogView.findViewById(R.id.tvMensaje);
mTvTitulo.setText(getArguments().getString(getString(R.string.bundle_titulo), ""));
mTvMensaje.setText(getArguments().getString(getString(R.string.bundle_mensaje), ""));
builder.setView(dialogView);
TranslateAnimation izqADerAnimacion = new TranslateAnimation(-loadingImage.getWidth(), dialogView.getWidth()+loadingImage.getWidth(), 0, 0);
izqADerAnimacion.setDuration(3500);
izqADerAnimacion.setRepeatCount(Animation.INFINITE);
loadingImage.startAnimation(izqADerAnimacion);
return builder.create();
}
}
But for some reason, the loadingImage.getWidth()
and dialogView.getWidth()
are returning 0
. What can I do to solve this without hardcoding the starting and finishing positions?