Skip to content

Commit b640078

Browse files
pekingmehunterstich
authored andcommitted
[ButtonGroup] Fixed the bug of size morph not working with layout_weight.
PiperOrigin-RevId: 732281281
1 parent 37a84d5 commit b640078

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/java/com/google/android/material/button/MaterialButton.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@
5050
import android.util.Log;
5151
import android.view.Gravity;
5252
import android.view.View;
53+
import android.view.ViewGroup;
5354
import android.view.accessibility.AccessibilityEvent;
5455
import android.view.accessibility.AccessibilityNodeInfo;
5556
import android.widget.Button;
5657
import android.widget.Checkable;
5758
import android.widget.CompoundButton;
5859
import android.widget.LinearLayout;
60+
import android.widget.LinearLayout.LayoutParams;
5961
import androidx.annotation.AttrRes;
6062
import androidx.annotation.ColorInt;
6163
import androidx.annotation.ColorRes;
@@ -528,7 +530,16 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
528530
originalWidth = UNSET;
529531
}
530532
if (originalWidth == UNSET) {
531-
originalWidth = right - left;
533+
originalWidth = getMeasuredWidth();
534+
if (getParent() instanceof MaterialButtonGroup) {
535+
ViewGroup.LayoutParams params = getLayoutParams();
536+
if (params instanceof LayoutParams) {
537+
LayoutParams linearParams = (LayoutParams) params;
538+
if (linearParams.weight != 0) {
539+
linearParams.width = getMeasuredWidth();
540+
}
541+
}
542+
}
532543
}
533544

534545
if (allowedWidthDecrease == UNSET) {

0 commit comments

Comments
 (0)