我已经使用recyclerview实现了一个库,并且我已经向viewholder添加了一个onLayoutChangeListener,这样一旦计算了布局,就会更改imageview的高度以匹配图像的宽高比.它在第一次打开活动,旋转设备或解锁屏幕时工作正常,但是当从另一个活动返回时它不起作用.执行该方法,但imageview不会更改.什么可能导致这个?
image.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) {
ImageView img = (ImageView) v;
Bitmap bm = ((BitmapDrawable) img.getDrawable()).getBitmap();
img.getLayoutParams().height = Utils.scaledHeight(bm.getWidth(), bm.getHeight(), img.getWidth());
img.removeOnLayoutChangeListener(this);
}
});
Run Code Online (Sandbox Code Playgroud)
调试器显示正确设置的高度,但显示的imageview不是它应该的样子.