summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Banes <chrisbanes@google.com>2015-08-18 15:46:28 +0100
committerDanny Baumann <dannybaumann@web.de>2016-01-13 11:35:13 +0100
commit6f0a2cb4415e2e170528c038a8f1cc2f68f60c3c (patch)
tree015d508e827a9ba247fa4929e0df19ad93e0a23f
parent2ae0ed11526a7adc53bc896fea5688e03ef429da (diff)
downloadandroid_frameworks_support-6f0a2cb4415e2e170528c038a8f1cc2f68f60c3c.tar.gz
android_frameworks_support-6f0a2cb4415e2e170528c038a8f1cc2f68f60c3c.tar.bz2
android_frameworks_support-6f0a2cb4415e2e170528c038a8f1cc2f68f60c3c.zip
Make sure that AppBarLayout is laid out correctly
Currently, the scrolling view of a AppBarLayout relies on CoLs pre draw listener to move itself. This is problematic for things like activity transitions which rely on correct position after a layout. BUG: 23307267 Change-Id: Ibf508908cd22ef29d2c3752b299b8ce5d6346b0a
-rw-r--r--design/api/current.txt1
-rw-r--r--design/src/android/support/design/widget/AppBarLayout.java23
2 files changed, 24 insertions, 0 deletions
diff --git a/design/api/current.txt b/design/api/current.txt
index de4e09b1d9..ff682ee6f5 100644
--- a/design/api/current.txt
+++ b/design/api/current.txt
@@ -61,6 +61,7 @@ package android.support.design.widget {
method public int getOverlayTop();
method public boolean layoutDependsOn(android.support.design.widget.CoordinatorLayout, android.view.View, android.view.View);
method public boolean onDependentViewChanged(android.support.design.widget.CoordinatorLayout, android.view.View, android.view.View);
+ method public boolean onLayoutChild(android.support.design.widget.CoordinatorLayout, android.view.View, int);
method public boolean onMeasureChild(android.support.design.widget.CoordinatorLayout, android.view.View, int, int, int, int);
method public void setOverlayTop(int);
}
diff --git a/design/src/android/support/design/widget/AppBarLayout.java b/design/src/android/support/design/widget/AppBarLayout.java
index 78f8f9fb16..5cb8b733eb 100644
--- a/design/src/android/support/design/widget/AppBarLayout.java
+++ b/design/src/android/support/design/widget/AppBarLayout.java
@@ -1267,8 +1267,30 @@ public class AppBarLayout extends LinearLayout {
}
@Override
+ public boolean onLayoutChild(CoordinatorLayout parent, View child, int layoutDirection) {
+ // First lay out the child as normal
+ super.onLayoutChild(parent, child, layoutDirection);
+
+ // Now offset us correctly to be in the correct position. This is important for things
+ // like activity transitions which rely on accurate positioning after the first layout.
+ final List<View> dependencies = parent.getDependencies(child);
+ for (int i = 0, z = dependencies.size(); i < z; i++) {
+ if (updateOffset(parent, child, dependencies.get(i))) {
+ // If we updated the offset, break out of the loop now
+ break;
+ }
+ }
+ return true;
+ }
+
+ @Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child,
View dependency) {
+ updateOffset(parent, child, dependency);
+ return false;
+ }
+
+ private boolean updateOffset(CoordinatorLayout parent, View child, View dependency) {
final CoordinatorLayout.Behavior behavior =
((CoordinatorLayout.LayoutParams) dependency.getLayoutParams()).getBehavior();
if (behavior instanceof Behavior) {
@@ -1276,6 +1298,7 @@ public class AppBarLayout extends LinearLayout {
final int offset = ((Behavior) behavior).getTopBottomOffsetForScrollingSibling();
setTopAndBottomOffset(dependency.getHeight() + offset
- getOverlapForOffset(dependency, offset));
+ return true;
}
return false;
}