问题描述
使用Recyclerview展示一系列图片。使用fresco加载。为了让imageView自适应图片宽高比,所以fresco设置了DraweeController 计算大小。
这段代码在target Sdk version 17的情况下,是能正常工作,图片可以正常显示。比如5张图按顺序一一展示。后来我设置target sdk version 25,代码未更改的情况下,5张图都有执行加载,但是5张图的位置叠加到一起,只能看到一张图片。我改为target sdk version 17又能正常工作了。。。
求教这是什么情况。毕竟android O都出来了。。。。
布局文件
<?xml version='1.0' encoding='utf-8'?><LinearLayout android:id='@+id/activity_circle_details'xmlns:android='http://schemas.android.com/apk/res/android'xmlns:fresco='http://schemas.android.com/apk/res-auto'android:layout_width='match_parent'android:layout_height='wrap_content'android:orientation='vertical'android:background='@color/white'><TextView android: android:layout_width='match_parent' android:layout_height='wrap_content' android:text='TextView' android:textSize='17sp' android:layout_margin='5dp' android:lineSpacingMultiplier='1.5' android:textColor='@color/black' /><com.facebook.drawee.view.SimpleDraweeView android: android:layout_width='match_parent' android:layout_height='wrap_content' android:layout_marginLeft='1dp' android:layout_marginRight='1dp' android:layout_marginBottom='5dp' fresco:placeholderImage='@mipmap/img_empty' fresco:placeholderImageScaleType='fitCenter' fresco:failureImage='@mipmap/img_error' /></LinearLayout>
RecyclerView.Adapter在onBindViewHolder中调用的关键代码。data是bean,getImage获取图片url
if(data.getImage()!=null && data.getImage().length()>0) { imageView.setVisibility(View.VISIBLE); //imageView.setImageURI(data.getImage()); setControllerListener(imageView, data.getImage(),Tools.getScreenWidth(CircleDetailsActivity.this));
Fresco的代码
/*** * 根据图片大小,更新view的大小自适应图片,按宽高比缩放 * 不知道为什么。targetVersion必须为4.2. 如果我设置为7.1则会发生图像覆盖的现象只能看到最后一张图 * @param simpleDraweeView * @param imagePath * @param imageWidth */public static void setControllerListener(final SimpleDraweeView simpleDraweeView, String imagePath, final int imageWidth) { final ViewGroup.LayoutParams layoutParams = simpleDraweeView.getLayoutParams(); ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {@Overridepublic void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) { if (imageInfo == null) {return; } int height = imageInfo.getHeight(); int width = imageInfo.getWidth(); layoutParams.width = imageWidth; layoutParams.height = (int) ((float) (imageWidth * height) / (float) width); simpleDraweeView.setLayoutParams(layoutParams);}@Overridepublic void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) { Log.d('TAG', 'Intermediate image received');}@Overridepublic void onFailure(String id, Throwable throwable) { throwable.printStackTrace();} }; DraweeController controller = Fresco.newDraweeControllerBuilder().setControllerListener(controllerListener).setTapToRetryEnabled(true).setUri(Uri.parse(imagePath)).build(); simpleDraweeView.setController(controller);}
包引用
compile ’com.android.support:appcompat-v7:25.3.1’ compile ’com.facebook.fresco:fresco:0.13.0’ compile ’com.squareup.okhttp3:okhttp:3.7.0’ compile ’com.facebook.fresco:animated-gif:0.13.0’ compile ’com.facebook.fresco:imagepipeline-okhttp3:0.13.0+’ compile ’com.android.support:recyclerview-v7:25.3.1’ compile ’com.android.support:percent:25.3.1’ compile ’com.android.support:design:25.3.1’ compile ’com.android.support:support-v4:25.3.1’
问题解答
回答1:应该是布局问题。不能在scrollView中嵌套scrollView