New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layoutHelper设置setLayoutViewBindListener背景图片,滑动的时候背景会拉伸一下 #275

Closed
37Jayden opened this Issue Dec 22, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@37Jayden

37Jayden commented Dec 22, 2017

private static class BindListener implements BaseLayoutHelper.LayoutViewBindListener {
private String imgUrl;

    public BindListener(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    @Override
    public void onBind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
        //loading image
       

    }
}

给layoutHelper设置背景时,layoutView.layoutView.getWidth()高度会变,怀疑是导致图片变形的原因,layoutView我返回的是
mLayoutManager.setLayoutViewFactory(new LayoutViewFactory() {
@override
public View generateLayoutView(@nonnull Context context) {
ImageView imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
return imageView;
}
});

@zsndev

This comment has been minimized.

Show comment
Hide comment
@zsndev

zsndev Dec 22, 2017

我也遇到了同样的问题,在列表滑动时,区域背景图片的宽高会改变,于是导致背景imageview centerCrop切图出现问题

zsndev commented Dec 22, 2017

我也遇到了同样的问题,在列表滑动时,区域背景图片的宽高会改变,于是导致背景imageview centerCrop切图出现问题

@longerian

This comment has been minimized.

Show comment
Hide comment
@longerian

longerian Dec 22, 2017

Contributor

调用 VirtualLayoutManager的 setRecycleOffset() 方法试试,它会延迟一段距离回收滑出屏幕的item。这样背景区域能保持,就不会变现。

Contributor

longerian commented Dec 22, 2017

调用 VirtualLayoutManager的 setRecycleOffset() 方法试试,它会延迟一段距离回收滑出屏幕的item。这样背景区域能保持,就不会变现。

@zsndev

This comment has been minimized.

Show comment
Hide comment
@zsndev

zsndev Dec 24, 2017

@longerian 试了试setRecycleOffset()方法,但并没有起作用。后来仔细观察了下,发现当layoutHelper的元素不能同时在一屏时下拉必定会触发背景变形的问题,所以猜测layoutHelper在有未显示元素时,不清楚自己的区域到底有多大,在可见元素变化时会动态计算区域大小,并调节背景view的大小,于是就导致了背景view中图片会根据view的大小去调整自己的显示。最后我通过把背景imageview的scaleType设置为matrix,这样就不会跟随imageview的宽高进行变化,同时根据不同手机的dpi提前调整好背景图片的尺寸后,再放入imageview中就解决了问题。

zsndev commented Dec 24, 2017

@longerian 试了试setRecycleOffset()方法,但并没有起作用。后来仔细观察了下,发现当layoutHelper的元素不能同时在一屏时下拉必定会触发背景变形的问题,所以猜测layoutHelper在有未显示元素时,不清楚自己的区域到底有多大,在可见元素变化时会动态计算区域大小,并调节背景view的大小,于是就导致了背景view中图片会根据view的大小去调整自己的显示。最后我通过把背景imageview的scaleType设置为matrix,这样就不会跟随imageview的宽高进行变化,同时根据不同手机的dpi提前调整好背景图片的尺寸后,再放入imageview中就解决了问题。

@longerian

This comment has been minimized.

Show comment
Hide comment
@longerian

longerian Dec 25, 2017

Contributor

@zsndev 是的,所以setRecycleOffset()可以给一个半屏的高度,让屏幕外的内容也有机会创建处理,这样layoutHelper就能尽可能知道它的真实区域大小,当然可能也不够彻底,你的办法应该更靠谱。

Contributor

longerian commented Dec 25, 2017

@zsndev 是的,所以setRecycleOffset()可以给一个半屏的高度,让屏幕外的内容也有机会创建处理,这样layoutHelper就能尽可能知道它的真实区域大小,当然可能也不够彻底,你的办法应该更靠谱。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment