我已经编写了简单的帮助程序,该帮助程序会考虑添加布局完成侦听器,并在布局过程完成时调用(imageView)。
public class PicassoDelegate {
private RequestCreator mRequestCreator;
public PicassoDelegate(ImageView target, RequestCreator requestCreator) {
if (target.getWidth() > 0 && target.getHeight() > 0) {
complete(target, requestCreator);
} else {
mRequestCreator = requestCreator;
target.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
v.removeOnLayoutChangeListener(this);
complete((ImageView) v, mRequestCreator);
}
});
}
}
private void complete(ImageView target, RequestCreator requestCreator) {
if (target.getWidth() > 0 && target.getHeight() > 0) {
requestCreator.resize(target.getWidth(), target.getHeight());
}
requestCreator.into(target);
}
}
因此,您可以像在片段的onViewCreated()中那样轻松地使用它
new PicassoDelegate(customerPhoto, Picasso.with(getActivity()).load(user.getPhotoUrl()).centerCrop())
java.lang.IllegalArgumentException: At least one dimension has to be positive number.
旋转错误,这是在片段中,关于为什么会发生这种情况的任何想法?