Skip to content

Commit

Permalink
aspect ratio updates after layout completion
Browse files Browse the repository at this point in the history
  • Loading branch information
kbhardwaj123 committed Apr 7, 2020
1 parent 1dc0dec commit 47c1894
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,13 @@ public void onResume() {
.setVisibility(View.GONE);
}
media = detailProvider.getMediaAtPosition(index);
displayMediaDetails();

scrollView.post(new Runnable() {
@Override
public void run() {
displayMediaDetails();
}
});
}

private void displayMediaDetails() {
Expand All @@ -246,21 +252,14 @@ private void displayMediaDetails() {

private void updateAspectRatio(ImageInfo imageInfo) {
if (imageInfo != null) {
int screenWidth = getScreenWidth(getContext());
int screenWidth = scrollView.getWidth();
int finalHeight = (screenWidth*imageInfo.getHeight()) / imageInfo.getWidth();
ViewGroup.LayoutParams params = image.getLayoutParams();
params.height = finalHeight;
image.setLayoutParams(params);
}
}

private int getScreenWidth(Context context) {
DisplayMetrics dm = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(dm);
return dm.widthPixels;
}

private final ControllerListener aspectRatioListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
Expand Down

0 comments on commit 47c1894

Please # to comment.