@@ -281,12 +281,12 @@ private int calculateImageHeight(FeedPostMediaItemAsset asset, int displayWidth)
281281 // Calculate height based on aspect ratio and display width
282282 int calculatedHeight = (int ) (displayWidth / aspectRatio );
283283
284- // Set minimum and maximum bounds to prevent extreme values
284+ // Set minimum bound to prevent extremely small images
285285 int minHeight = context .getResources ().getDimensionPixelSize (R .dimen .feed_image_half_height );
286- int maxHeight = context .getResources ().getDimensionPixelSize (R .dimen .feed_image_height ) * 2 ;
287286
288- // Ensure the height is within reasonable bounds
289- return Math .max (minHeight , Math .min (calculatedHeight , maxHeight ));
287+ // Ensure the height is at least the minimum height
288+ // but allow it to be as tall as needed by the aspect ratio
289+ return Math .max (minHeight , calculatedHeight );
290290 }
291291
292292 enum FeedPostType {
@@ -486,21 +486,12 @@ private void bindSingleImagePost(FeedPost post) {
486486 if (bestSizeAsset != null && bestSizeAsset .getSrc () != null ) {
487487 mediaContainer .setVisibility (View .VISIBLE );
488488
489- // Get the screen width for calculating the appropriate height
490- int screenWidth = context .getResources ().getDisplayMetrics ().widthPixels ;
491-
492- // Calculate the image height based on the aspect ratio
493- int calculatedHeight = calculateImageHeight (bestSizeAsset , screenWidth );
489+ // Don't set fixed height - let the image determine its own size
490+ // with adjustViewBounds
494491
495- // Set the calculated height before loading the image
496- // This prevents the layout from jumping when the image loads
497- mediaImageView .getLayoutParams ().height = calculatedHeight ;
498- mediaImageView .requestLayout ();
499-
500- // Load image with exact calculated dimensions to prevent scaling issues
492+ // Load image without overriding dimensions
501493 Glide .with (context )
502494 .load (bestSizeAsset .getSrc ())
503- .override (screenWidth , calculatedHeight )
504495 .transition (DrawableTransitionOptions .withCrossFade (300 ))
505496 .error (R .drawable .image_placeholder )
506497 .into (mediaImageView );
@@ -662,15 +653,15 @@ private void setupImageGrid(List<FeedPostMediaItem> mediaItems) {
662653 params .height = GridLayout .LayoutParams .MATCH_PARENT ;
663654 imageGridLayout .addView (imageView , params );
664655 } else if (count == 2 ) {
665- // Two images side by side (only handles 1-2 images now)
656+ // Two images stacked vertically
666657 for (int i = 0 ; i < count ; i ++) {
667658 ImageView imageView = createImageView (mediaItems .get (i ));
668659 GridLayout .LayoutParams params = new GridLayout .LayoutParams (
669- GridLayout .spec (0 , 2 , 1f ),
670- GridLayout .spec (i , 1 , 1f ));
671- params .width = 0 ;
672- params .height = GridLayout .LayoutParams .MATCH_PARENT ;
673- params .setMargins (i > 0 ? 2 : 0 , 0 , i > 0 ? 0 : 2 , 0 );
660+ GridLayout .spec (i , 1 , 1f ), // i'th row, 1 row, 1f weight
661+ GridLayout .spec (0 , 1 , 1f )); // 0th column, 1 column, 1f weight
662+ params .width = GridLayout . LayoutParams . MATCH_PARENT ;
663+ params .height = GridLayout .LayoutParams .WRAP_CONTENT ;
664+ params .setMargins (0 , i > 0 ? 4 : 0 , 0 , i < count - 1 ? 4 : 0 ); // Vertical margins between images
674665 imageGridLayout .addView (imageView , params );
675666 }
676667 }
@@ -785,45 +776,46 @@ private void loadImageIntoView(FeedPostMediaItem mediaItem, ImageView imageView)
785776 */
786777 private ImageView createImageView (FeedPostMediaItem mediaItem ) {
787778 ImageView imageView = new ImageView (context );
788- imageView .setBackgroundColor (context .getResources ().getColor (android .R .color .darker_gray , null ));
789779
790- // Calculate initial image height based on screen width and estimated grid column width
780+ // Set up ImageView properties similar to single image view
781+ imageView .setScaleType (ImageView .ScaleType .FIT_CENTER );
782+ imageView .setAdjustViewBounds (true );
783+
784+ // Use full screen width for stacked images
791785 int screenWidth = context .getResources ().getDisplayMetrics ().widthPixels ;
792- int estimatedWidth = screenWidth / 2 ; // Grid images usually take about half the screen width
793- int initialHeight = getDefaultImageHeight (); // Default fallback height
794786
795787 // Load image using Glide if media item has sizes
796788 if (mediaItem .getSizes () != null && !mediaItem .getSizes ().isEmpty ()) {
797789 FeedPostMediaItemAsset bestSizeAsset = selectBestImageSize (mediaItem .getSizes ());
798790
799791 if (bestSizeAsset != null && bestSizeAsset .getSrc () != null ) {
800- // Calculate height based on aspect ratio before loading
801- if (bestSizeAsset .getW () != null && bestSizeAsset .getH () != null ) {
802- initialHeight = calculateImageHeight (bestSizeAsset , estimatedWidth );
803- }
804-
805- // Set the calculated height
792+ // Set up layout parameters for wrap_content height
806793 ViewGroup .LayoutParams layoutParams = new ViewGroup .LayoutParams (
807- ViewGroup .LayoutParams .MATCH_PARENT , initialHeight );
794+ ViewGroup .LayoutParams .MATCH_PARENT ,
795+ ViewGroup .LayoutParams .WRAP_CONTENT );
808796 imageView .setLayoutParams (layoutParams );
809797
798+ // Let Glide load the image with natural aspect ratio
810799 Glide .with (context )
811800 .load (bestSizeAsset .getSrc ())
812- .override (estimatedWidth , initialHeight )
813801 .transition (DrawableTransitionOptions .withCrossFade ())
814802 .error (R .drawable .image_placeholder )
815803 .into (imageView );
816804 } else {
817- // Set default height if no valid asset
805+ // Set fallback if no valid asset
818806 ViewGroup .LayoutParams layoutParams = new ViewGroup .LayoutParams (
819- ViewGroup .LayoutParams .MATCH_PARENT , initialHeight );
807+ ViewGroup .LayoutParams .MATCH_PARENT ,
808+ ViewGroup .LayoutParams .WRAP_CONTENT );
820809 imageView .setLayoutParams (layoutParams );
810+ imageView .setImageResource (R .drawable .image_placeholder );
821811 }
822812 } else {
823- // Set default height if no sizes
813+ // Set fallback if no sizes
824814 ViewGroup .LayoutParams layoutParams = new ViewGroup .LayoutParams (
825- ViewGroup .LayoutParams .MATCH_PARENT , initialHeight );
815+ ViewGroup .LayoutParams .MATCH_PARENT ,
816+ ViewGroup .LayoutParams .WRAP_CONTENT );
826817 imageView .setLayoutParams (layoutParams );
818+ imageView .setImageResource (R .drawable .image_placeholder );
827819 }
828820
829821 // Set click listener
@@ -874,21 +866,10 @@ private void bindTaskPost(FeedPost post) {
874866
875867 if (bestSizeAsset != null && bestSizeAsset .getSrc () != null ) {
876868 mediaContainer .setVisibility (View .VISIBLE );
877- // Get the screen width for calculating the appropriate height
878- int screenWidth = context .getResources ().getDisplayMetrics ().widthPixels ;
879-
880- // Calculate the image height based on the aspect ratio
881- int calculatedHeight = calculateImageHeight (bestSizeAsset , screenWidth );
882-
883- // Set the calculated height before loading the image
884- // This prevents the layout from jumping when the image loads
885- mediaImageView .getLayoutParams ().height = calculatedHeight ;
886- mediaImageView .requestLayout ();
887869
888- // Load image with exact calculated dimensions to prevent scaling issues
870+ // Load image without overriding dimensions
889871 Glide .with (context )
890872 .load (bestSizeAsset .getSrc ())
891- .override (screenWidth , calculatedHeight )
892873 .transition (DrawableTransitionOptions .withCrossFade (300 ))
893874 .error (R .drawable .image_placeholder )
894875 .into (mediaImageView );
0 commit comments