Skip to content

Commit

Permalink
修复详情页连续加载多张图片导致后续图片都跟第一张图片相同高度的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
sendtion committed Jul 10, 2018
1 parent 7075564 commit e4c9fda
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions xrichtext/src/main/java/com/sendtion/xrichtext/RichTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,22 @@ public void addImageViewAtIndex(final int index, final String imagePath) {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
//调整imageView的高度,根据宽度等比获得高度
int imageHeight = allLayout.getWidth() * resource.getHeight() / resource.getWidth();
int imageHeight ; //解决连续加载多张图片导致后续图片都跟第一张高度相同的问题
if (rtImageHeight > 0) {
imageHeight = rtImageHeight;
} else {
imageHeight = allLayout.getWidth() * resource.getHeight() / resource.getWidth();
}
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, imageHeight);//固定图片高度,记得设置裁剪剧中
lp.bottomMargin = 10;
lp.bottomMargin = rtImageBottom;
imageView.setLayoutParams(lp);

imageView.setScaleType(ImageView.ScaleType.FIT_XY);
if (rtImageHeight > 0) {
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
} else {
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
}
imageView.setImageBitmap(resource);
// 不能使用centerCrop,否则图片显示不全
// GlideApp.with(getContext()).load(imagePath)
Expand All @@ -245,17 +254,24 @@ public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? sup

// 调整imageView的高度,根据宽度等比获得高度
Bitmap bmp = BitmapFactory.decodeFile(imagePath);
if (rtImageHeight == 0) {
rtImageHeight = allLayout.getWidth() * bmp.getHeight() / bmp.getWidth();
int imageHeight ; //解决连续加载多张图片导致后续图片都跟第一张高度相同的问题
if (rtImageHeight > 0) {
imageHeight = rtImageHeight;
} else {
imageHeight = allLayout.getWidth() * bmp.getHeight() / bmp.getWidth();
}
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, rtImageHeight);//固定图片高度,记得设置裁剪剧中
LayoutParams.MATCH_PARENT, imageHeight);//固定图片高度,记得设置裁剪剧中
lp.bottomMargin = rtImageBottom;
imageView.setLayoutParams(lp);

imageView.setScaleType(ImageView.ScaleType.FIT_XY);
GlideApp.with(getContext()).load(imagePath)
.placeholder(R.drawable.img_load_fail).error(R.drawable.img_load_fail).into(imageView);
if (rtImageHeight > 0){
GlideApp.with(getContext()).load(imagePath).centerCrop()
.placeholder(R.drawable.img_load_fail).error(R.drawable.img_load_fail).into(imageView);
} else {
GlideApp.with(getContext()).load(imagePath)
.placeholder(R.drawable.img_load_fail).error(R.drawable.img_load_fail).into(imageView);
}
}

// onActivityResult无法触发动画,此处post处理
Expand Down

0 comments on commit e4c9fda

Please sign in to comment.