summaryrefslogtreecommitdiff
path: root/src/com/android/calculator2/CalculatorScrollView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/calculator2/CalculatorScrollView.java')
-rw-r--r--src/com/android/calculator2/CalculatorScrollView.java25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/com/android/calculator2/CalculatorScrollView.java b/src/com/android/calculator2/CalculatorScrollView.java
index bcf5650..018ad10 100644
--- a/src/com/android/calculator2/CalculatorScrollView.java
+++ b/src/com/android/calculator2/CalculatorScrollView.java
@@ -22,6 +22,10 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
+import static android.view.View.MeasureSpec.UNSPECIFIED;
+import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
+import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
+
public class CalculatorScrollView extends HorizontalScrollView {
public CalculatorScrollView(Context context) {
@@ -36,17 +40,26 @@ public class CalculatorScrollView extends HorizontalScrollView {
super(context, attrs, defStyleAttr);
}
+ private static int getChildMeasureSpecCompat(int spec, int padding, int childDimension) {
+ if (MeasureSpec.getMode(spec) == UNSPECIFIED
+ && (childDimension == MATCH_PARENT || childDimension == WRAP_CONTENT)) {
+ final int size = Math.max(0, MeasureSpec.getSize(spec) - padding);
+ return MeasureSpec.makeMeasureSpec(size, UNSPECIFIED);
+ }
+ return ViewGroup.getChildMeasureSpec(spec, padding, childDimension);
+ }
+
@Override
protected void measureChild(View child, int parentWidthMeasureSpec,
int parentHeightMeasureSpec) {
// Allow child to be as wide as they want.
parentWidthMeasureSpec = MeasureSpec.makeMeasureSpec(
- MeasureSpec.getSize(parentWidthMeasureSpec), MeasureSpec.UNSPECIFIED);
+ MeasureSpec.getSize(parentWidthMeasureSpec), UNSPECIFIED);
final ViewGroup.LayoutParams lp = child.getLayoutParams();
- final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec,
+ final int childWidthMeasureSpec = getChildMeasureSpecCompat(parentWidthMeasureSpec,
0 /* padding */, lp.width);
- final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec,
+ final int childHeightMeasureSpec = getChildMeasureSpecCompat(parentHeightMeasureSpec,
getPaddingTop() + getPaddingBottom(), lp.height);
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
@@ -57,12 +70,12 @@ public class CalculatorScrollView extends HorizontalScrollView {
int parentHeightMeasureSpec, int heightUsed) {
// Allow child to be as wide as they want.
parentWidthMeasureSpec = MeasureSpec.makeMeasureSpec(
- MeasureSpec.getSize(parentWidthMeasureSpec), MeasureSpec.UNSPECIFIED);
+ MeasureSpec.getSize(parentWidthMeasureSpec), UNSPECIFIED);
final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
- final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec,
+ final int childWidthMeasureSpec = getChildMeasureSpecCompat(parentWidthMeasureSpec,
lp.leftMargin + lp.rightMargin, lp.width);
- final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec,
+ final int childHeightMeasureSpec = getChildMeasureSpecCompat(parentHeightMeasureSpec,
getPaddingTop() + getPaddingBottom() + lp.topMargin + lp.bottomMargin, lp.height);
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);