From b382ebecc3703569fff15d93bba90ad36f1f1298 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 16 Jul 2021 20:32:05 +0800 Subject: Center the FloatingActionButton in PostGalleryActivity. --- .../RedditGallerySubmissionRecyclerViewAdapter.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java index 87853c93..97509970 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java @@ -9,6 +9,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.widget.ImageView; import android.widget.ProgressBar; @@ -164,7 +165,19 @@ public class RedditGallerySubmissionRecyclerViewAdapter extends RecyclerView.Ada fab.setBackgroundTintList(ColorStateList.valueOf(customThemeWrapper.getColorPrimaryLightTheme())); fab.setImageTintList(ColorStateList.valueOf(customThemeWrapper.getFABIconColor())); - itemView.setOnClickListener(view -> itemClickListener.onAddImageClicked()); + itemView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + itemView.getViewTreeObserver().removeOnGlobalLayoutListener(this); + int width = itemView.getMeasuredWidth(); + ViewGroup.LayoutParams params = itemView.getLayoutParams(); + params.height = width; + itemView.setLayoutParams(params); + } + }); + + fab.setOnClickListener(view -> itemClickListener.onAddImageClicked()); + itemView.setOnClickListener(view -> fab.performClick()); } } -- cgit v1.2.3