summaryrefslogtreecommitdiffstats
path: root/core/java/android/view/ViewGroup.java
diff options
context:
space:
mode:
authorPhilip Milne <pmilne@google.com>2012-01-26 16:55:30 -0800
committerPhilip Milne <pmilne@google.com>2012-02-13 16:55:57 -0800
commitd7dd89095ff2041f0793317c4ee8e8be49388148 (patch)
tree9ee7b1cf9fa0261b0c6196c3d1c8e0c42880f3a5 /core/java/android/view/ViewGroup.java
parent07f941f026ed2aef8945d0d44134162b3db50eb5 (diff)
downloadframeworks_base-d7dd89095ff2041f0793317c4ee8e8be49388148.zip
frameworks_base-d7dd89095ff2041f0793317c4ee8e8be49388148.tar.gz
frameworks_base-d7dd89095ff2041f0793317c4ee8e8be49388148.tar.bz2
New hooks to allow layouts to improve their performance by doing more caching
This change allows layouts to be notified of changes to LayoutParameters that have occurred between layout operations. If an assignment is made to the fields of LayoutParams instances that are already in use, cachced data may become inconsistent with the new values. For complex layouts, like GridLayout, in which the layout parameters define the structure of the layout, caching could have caused ArrayOutOfBoundsException to be raised without this change. This case is rare in normal code as initialisation is typically performed once. Its nevertheless possible and much more likely in environments like design tools where layout parametrs may be being edited on the fly. Prevent errors as follows (belt and braces): 1. Change javadoc to request that changes to the fields of LayoutParams be accompanied with a call to View.setLayoutParams(). (This calls requestLayout() which was what the previous javadoc advised.) Provide a (for now, private) hook for layouts with caches to receive notification of such calls so they can invalidate any relevant internal state. 2. For GridLayout, we cannot clone layout parameters as traditional Java grids do without retaining two complete copies because of the public getLayoutParameters() method on View. Retaining two copies is wasteful on constrainted devices. Instead, we keep just one copy and compute a hashCode for the critical fields of a GridLayout's layoutParams. The hashChode is checked it prior to all layout operations; clearing the cache and logging a warning when changes are detected, so that developers can fix their code to provide the call to setLayoutParams() as above. Change-Id: I819ea65ec0ab82202e2f94fd5cd3ae2723c1a9a0
Diffstat (limited to 'core/java/android/view/ViewGroup.java')
-rw-r--r--core/java/android/view/ViewGroup.java24
1 files changed, 16 insertions, 8 deletions
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index d3af618..f9f5469 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -5203,6 +5203,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
return true;
}
+ /** @hide */
+ protected void onSetLayoutParams(View child, LayoutParams layoutParams) {
+ }
+
/**
* LayoutParams are used by views to tell their parents how they want to be
* laid out. See
@@ -5411,29 +5415,33 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
*/
public static class MarginLayoutParams extends ViewGroup.LayoutParams {
/**
- * The left margin in pixels of the child. Whenever this value is changed, a call to
- * {@link android.view.View#requestLayout()} needs to be done.
+ * The left margin in pixels of the child.
+ * Call {@link ViewGroup#setLayoutParams(LayoutParams)} after reassigning a new value
+ * to this field.
*/
@ViewDebug.ExportedProperty(category = "layout")
public int leftMargin;
/**
- * The top margin in pixels of the child. Whenever this value is changed, a call to
- * {@link android.view.View#requestLayout()} needs to be done.
+ * The top margin in pixels of the child.
+ * Call {@link ViewGroup#setLayoutParams(LayoutParams)} after reassigning a new value
+ * to this field.
*/
@ViewDebug.ExportedProperty(category = "layout")
public int topMargin;
/**
- * The right margin in pixels of the child. Whenever this value is changed, a call to
- * {@link android.view.View#requestLayout()} needs to be done.
+ * The right margin in pixels of the child.
+ * Call {@link ViewGroup#setLayoutParams(LayoutParams)} after reassigning a new value
+ * to this field.
*/
@ViewDebug.ExportedProperty(category = "layout")
public int rightMargin;
/**
- * The bottom margin in pixels of the child. Whenever this value is changed, a call to
- * {@link android.view.View#requestLayout()} needs to be done.
+ * The bottom margin in pixels of the child.
+ * Call {@link ViewGroup#setLayoutParams(LayoutParams)} after reassigning a new value
+ * to this field.
*/
@ViewDebug.ExportedProperty(category = "layout")
public int bottomMargin;