Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMOB-8772: Android: Alignment Issues on Android, layout appears broken #2058

Merged
merged 2 commits into from
Apr 25, 2012
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,25 @@ protected LayoutParams generateDefaultLayoutParams()
return params;
}

private int getAsPercentageValue(double percentage, int value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably could just make this static.

{
return (int) Math.round((percentage / 100.0) * value);
}

protected int getViewWidthPadding(View child, int parentWidth)
{
LayoutParams p = (LayoutParams) child.getLayoutParams();
int padding = 0;
if (p.optionLeft != null) {
if (p.optionLeft.isUnitPercent()) {
padding += (int) ((p.optionLeft.getValue() / 100.0) * parentWidth);
padding += getAsPercentageValue(p.optionLeft.getValue(), parentWidth);
} else {
padding += p.optionLeft.getAsPixels(this);
}
}
if (p.optionRight != null) {
if (p.optionRight.isUnitPercent()) {
padding += (int) ((p.optionRight.getValue() / 100.0) * parentWidth);
padding += getAsPercentageValue(p.optionRight.getValue(), parentWidth);
} else {
padding += p.optionRight.getAsPixels(this);
}
Expand All @@ -235,14 +240,14 @@ protected int getViewHeightPadding(View child, int parentHeight)
int padding = 0;
if (p.optionTop != null) {
if (p.optionTop.isUnitPercent()) {
padding += (int) ((p.optionTop.getValue() / 100.0) * parentHeight);
padding += getAsPercentageValue(p.optionTop.getValue(), parentHeight);
} else {
padding += p.optionTop.getAsPixels(this);
}
}
if (p.optionBottom != null) {
if (p.optionBottom.isUnitPercent()) {
padding += (int) ((p.optionBottom.getValue() / 100.0) * parentHeight);
padding += getAsPercentageValue(p.optionBottom.getValue(), parentHeight);
} else {
padding += p.optionBottom.getAsPixels(this);
}
Expand Down Expand Up @@ -321,7 +326,7 @@ protected void constrainChild(View child, int width, int wMode, int height, int
int childDimension = LayoutParams.WRAP_CONTENT;
if (p.optionWidth != null) {
if (p.optionWidth.isUnitPercent() && width > 0) {
childDimension = (int) ((p.optionWidth.getValue() / 100.0) * width);
childDimension = getAsPercentageValue(p.optionWidth.getValue(), width);
} else {
childDimension = p.optionWidth.getAsPixels(this);
}
Expand All @@ -345,7 +350,7 @@ protected void constrainChild(View child, int width, int wMode, int height, int
childDimension = LayoutParams.WRAP_CONTENT;
if (p.optionHeight != null) {
if (p.optionHeight.isUnitPercent() && height > 0) {
childDimension = (int) ((p.optionHeight.getValue() / 100.0) * height);
childDimension = getAsPercentageValue(p.optionHeight.getValue(), height);
} else {
childDimension = p.optionHeight.getAsPixels(this);
}
Expand Down