Closed LeonXtp closed 6 years ago
http://img.my.csdn.net/uploads/201707/17/1500281250_7285.gif 兄弟 帮个忙 希望描述详细一点啊,我这里就没翻车。 你是跑的我的demo吗?
@LeonXtp 发个demo工程给我调吧,感谢啊
@iielse 我是Nexus6P 7.1.2系统直接下载apk先体验的,然后出现了上面的问题。然后我拉代码跑工程还是一样,但是在小米Mi Max 7.0系统中运行跑起来又是正常的
@iielse e神,一加五也翻车了,运行demo出现一样的问题http://upload-images.jianshu.io/upload_images/2018741-f22add5f1676a879.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
我也遇到这个问题,刚好也是一加5,图片靠左垂直居中了,而没有整个垂直居中,希望帮忙解决下
我也遇到了这个问题。
这个问题我也遇到过,是由于首次创建的时候mWidth和mHeight没有初始值的原因,设置初始值就可以了
今天,我自己也遇到这个问题了。 原因就是 @hu670014125 所说的, 首次创建的时候mWidth和mHeight没有初始值。
如果显示的时候 动态创建imageWatcher
这样调用的API->ImageWatcher.Helper.with(this@BaseActivity).create()
这个时候直接show,mWidth,mHeight就都是0,这样查看大图的第一个平移效果计算的终点坐标就是错误的。
这里有几种方法: 第一种就是 imageWatcher的初始化 在 xml 布局里面写好 ,这样 调用的时候 mWidth, mHeight都会有值。 第二种就是 业务逻辑这里展示大图一般都是全屏展示的。直接 把 mWidth 赋值屏幕宽度,mHeight 赋值屏幕高度就可以。
第三种就是 在show的时候,假如宽高是0,把入参参数临时保存为成员变量,等 onSizeChanged被调用拿到宽高后, 再内部重新调用 show方法就可以了。
private boolean isInitLayout = false;
private ImageView initI;
private SparseArray<ImageView> initImageGroupList;
private List<Uri> initUrlList;
/**
* @param i 被点击的ImageView
* @param imageGroupList
* @param urlList 被加载的图片url列表,数量必须大于等于 imageGroupList.size。 且顺序应当和imageGroupList保持一致
*/
public void show(ImageView i, SparseArray<ImageView> imageGroupList, final List<Uri> urlList) {
if (i == null || imageGroupList == null || urlList == null || imageGroupList.size() < 1 ||
urlList.size() < imageGroupList.size()) {
String info = "i[" + i + "]";
info += "#imageGroupList " + (imageGroupList == null ? "null" : "size : " + imageGroupList.size());
info += "#urlList " + (urlList == null ? "null" : "size :" + urlList.size());
throw new IllegalArgumentException("error params \n" + info);
}
if (!isInitLayout) {
initI = i; //临时存储用户设置入参,onSizeChanged的时候使用
initImageGroupList = imageGroupList;
initUrlList = urlList;
return;
}
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mWidth = w;
mHeight = h;
maxTranslateX = mWidth / 2;
maxTranslateY = mHeight / 2;
if (!isInitLayout) {
isInitLayout = true; // 拿到了正确的宽高,重新继续 show的逻辑
new Handler().post(new Runnable() {
@Override
public void run() {
show(initI, initImageGroupList, initUrlList);
}
});
}
}
没有按照预期的方式显示,点击之后仅仅按列表里的大小显示,并且位置水平靠左垂直居中的。 效果图如下: http://upload-images.jianshu.io/upload_images/2018741-f22add5f1676a879.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240