summaryrefslogtreecommitdiff
path: root/core/java/android/view/ViewParent.java
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2014-12-18 15:22:26 -0800
committerAdam Powell <adamp@google.com>2015-11-19 09:31:56 -0800
commitc55d5072ac52cee1811b52406419228fa81119ce (patch)
treedf0dcdd6dab56a679b03c29f93e4a2f51f6ccd4a /core/java/android/view/ViewParent.java
parent6d198e8c968b038de1a38c230b87d9c93c1a9a4a (diff)
Add support for partial view layouts
Traditionally, when a view called requestLayout it would force recursive requestLayout calls for all parent views up the hierarchy. This meant that there was no way to determine at traversal time whether a parent view itself needed layout, or if just one of its descendants did. Add a ViewParent method requestPartialLayoutForChild(View). This lets a caller state that a particular child of a given parent needs a remeasure and relayout at its current measured size and position within that parent. This can help prevent the full-tree relayout often caused by otherwise trivial changes. Partial layouts are processed after any pending "full" relayout during ViewRoot traversals, but before drawing. Add a ViewGroup method requestLayoutForChild(View). This lets a ViewGroup decide whether it is more appropriate to request a traditional relayout or a partial layout for itself or just the child that changed. Add a ViewParent method findDependentLayoutAxes. This allows a caller to check if the ViewParent's layout is dependent on a specific direct child view along one or both axes. Called recursively, this can be used to determine if a change in a child view can be isolated to a partial layout, even if its direct parent's own layout is tied to its other ancestors. (e.g. MATCH_PARENT, LinearLayout weights) Implement ViewGroup#requestPartialLayoutForChild to call new ViewParent method findDependentLayoutAxes and based on the result, either request a full layout for itself or a partial layout for the child in question. Implement findDependentLayoutAxes for common framework ViewGroups. A private implementation in ViewGroup is available for use by framework classes that will deal with basic LayoutParams. These implementations specifically check for derived LayoutParams classes and abort the optimization if they find something beyond their expected parameter types. Change-Id: I0a1a9b79293d17d4fae8d9892b96d3586f9401ae
Diffstat (limited to 'core/java/android/view/ViewParent.java')
-rw-r--r--core/java/android/view/ViewParent.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/core/java/android/view/ViewParent.java b/core/java/android/view/ViewParent.java
index 07f1e2cbdb4f..6ae448a7e888 100644
--- a/core/java/android/view/ViewParent.java
+++ b/core/java/android/view/ViewParent.java
@@ -26,6 +26,11 @@ import android.view.accessibility.AccessibilityEvent;
*
*/
public interface ViewParent {
+ public static final int FLAG_LAYOUT_AXIS_HORIZONTAL = 1;
+ public static final int FLAG_LAYOUT_AXIS_VERTICAL = 2;
+ public static final int FLAG_LAYOUT_AXIS_ANY
+ = FLAG_LAYOUT_AXIS_HORIZONTAL | FLAG_LAYOUT_AXIS_VERTICAL;
+
/**
* Called when something has changed which has invalidated the layout of a
* child of this view parent. This will schedule a layout pass of the view
@@ -601,4 +606,48 @@ public interface ViewParent {
* @return true if the action was consumed by this ViewParent
*/
public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle arguments);
+
+ /**
+ * Called when a child of this ViewParent requires a relayout before
+ * the next frame is drawn. A call to {@link View#requestLayout() child.requestLayout()}
+ * will implicitly result in a call to
+ * <code>child.getParent().requestLayoutForChild(child)</code>. App code should not call this
+ * method directly. Call <code>child.requestLayout()</code> instead.
+ *
+ * <p>On versions of Android from API 23 and older, a call to {@link View#requestLayout()}
+ * would cause a matching call to <code>requestLayout</code> on each parent view up to
+ * the root. With the addition of <code>requestLayoutForChild</code> a view's parent may
+ * explicitly decide how to handle a layout request. This allows for optimizations when
+ * a view parent knows that a layout-altering change in a child will not affect its own
+ * measurement.</p>
+ *
+ * @param child Child requesting a layout
+ */
+ public void requestLayoutForChild(View child);
+
+ /**
+ * Determine which axes of this ViewParent's layout are dependent on the given
+ * direct child view. The returned value is a flag set that may contain
+ * {@link #FLAG_LAYOUT_AXIS_HORIZONTAL} and/or {@link #FLAG_LAYOUT_AXIS_VERTICAL}.
+ * {@link #FLAG_LAYOUT_AXIS_ANY} is provided as a shortcut for
+ * <code>FLAG_LAYOUT_AXIS_HORIZONTAL | FLAG_LAYOUT_AXIS_VERTICAL</code>.
+ *
+ * <p>The given child must be a direct child view. Implementations should throw
+ * {@link IllegalArgumentException} otherwise.</p>
+ *
+ * <p>The caller may specify which axes it cares about. This should be treated as a filter.
+ * Implementations should never return a result that would be different from
+ * <code>result & axisFilter</code>.</p>
+ *
+ * @param child Direct child of this ViewParent to check
+ * @param axisFilter Which axes to check for dependencies. Can be
+ * {@link #FLAG_LAYOUT_AXIS_HORIZONTAL}, {@link #FLAG_LAYOUT_AXIS_VERTICAL}
+ * or {@link #FLAG_LAYOUT_AXIS_ANY}.
+ * @return Axes of this ViewParent that depend on the given child's layout changes
+ *
+ * @see #FLAG_LAYOUT_AXIS_HORIZONTAL
+ * @see #FLAG_LAYOUT_AXIS_VERTICAL
+ * @see #FLAG_LAYOUT_AXIS_ANY
+ */
+ public int findDependentLayoutAxes(View child, int axisFilter);
}