Bläddra i källkod

Fix vibrating windows

Some windows with just the right amount of scrollable content would trigger the
removal of the bottom margin, however the new layout pass would show that the
content is no longer scrollable so the bottom margin would be reenabled.
This would cause the window to continously vibrate up and down.

This fix verifies the available space before adding the margin, and doesn't
add it, if it would cause the content to scroll.
Kevin Barry 10 år sedan
förälder
incheckning
781681a094

+ 17 - 2
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -9,6 +9,7 @@ import android.content.res.ColorStateList;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.Color;
+import android.graphics.Rect;
 import android.graphics.Typeface;
 import android.graphics.drawable.Drawable;
 import android.os.Build;
@@ -421,9 +422,23 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         } else {
             Resources r = getContext().getResources();
             buttonBarDivider.setVisibility(View.GONE);
+
             final int bottomMargin = r.getDimensionPixelSize(R.dimen.md_button_frame_vertical_padding);
-            setVerticalMargins(view.findViewById(R.id.buttonStackedFrame), bottomMargin, bottomMargin);
-            setVerticalMargins(view.findViewById(R.id.buttonDefaultFrame), bottomMargin, bottomMargin);
+
+            /* Only enable the bottom margin if our available window space can hold the margin,
+               we don't want to enable this and cause the content to scroll, which is bad
+               experience itself but it also causes a vibrating window as this will keep getting
+               enabled/disabled over and over again.
+             */
+            Rect maxWindowFrame = new Rect();
+            getWindow().getDecorView().getWindowVisibleDisplayFrame(maxWindowFrame);
+            int currentHeight = getWindow().getDecorView().getMeasuredHeight();
+            if (currentHeight + bottomMargin < maxWindowFrame.height()) {
+                setVerticalMargins(view.findViewById(R.id.buttonStackedFrame),
+                        bottomMargin, bottomMargin);
+                setVerticalMargins(view.findViewById(R.id.buttonDefaultFrame),
+                        bottomMargin, bottomMargin);
+            }
         }
     }