Skip to content
This repository has been archived by the owner on Mar 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #33 from rakshakhegde/master
Browse files Browse the repository at this point in the history
fix Incorrect computation of Label Height in some ConstraintLayout
  • Loading branch information
badoualy authored Jul 12, 2017
2 parents 4fbadcc + 8184a05 commit da76c72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,12 @@ private float getMaxLabelHeight() {
return showLabels ? maxLabelHeight + labelMarginTop : 0;
}

private void calculateMaxLabelHeight() {
private void calculateMaxLabelHeight(final int measuredWidth) {
if (!showLabels) return;

// gridWidth is the width of the grid assigned for the step indicator
int twoDp = getContext().getResources().getDimensionPixelSize(R.dimen.stpi_two_dp);
int gridWidth = getMeasuredWidth() / stepCount - twoDp;
int gridWidth = measuredWidth / stepCount - twoDp;

if (gridWidth <= 0) return;

Expand Down Expand Up @@ -1048,8 +1048,12 @@ private boolean isStepValid(final int stepPos) {

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Log.e("Yann", "onMeasure");
calculateMaxLabelHeight();
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);

int width = widthMode == MeasureSpec.EXACTLY ? widthSize : getSuggestedMinimumWidth();

calculateMaxLabelHeight(width);

// Compute the necessary height for the widget
int desiredHeight = (int) Math.ceil(
Expand All @@ -1059,12 +1063,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
getMaxLabelHeight()
);

int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);

int width = widthMode == MeasureSpec.EXACTLY ? widthSize : getSuggestedMinimumWidth();
int height = heightMode == MeasureSpec.EXACTLY ? heightSize : desiredHeight;

setMeasuredDimension(width, height);
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
android:layout_marginTop="32dp"
app:stpi_labels="@array/stepLabels"/>

</RelativeLayout>
</RelativeLayout>

0 comments on commit da76c72

Please sign in to comment.