我有一個cutstom DialogFragment
向用戶顯示加載消息。對於加載消息圖像,我創建了一個從屏幕左側(從屏幕外部開始)到屏幕右側(在屏幕之外完成)的動畫。要做到這一點,我想開始對y=-imageWith
和完成的動畫y=imageWith+dialogWith
的:從左側屏幕外部移動圖像到右側屏幕外部Android
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();
}
}
但由於某些原因,loadingImage.getWidth()
和dialogView.getWidth()
正在返回0
。我可以做什麼來解決這個問題,而不用硬編碼的開始和結束位置?