diff options
author | Adam Powell <adamp@google.com> | 2012-09-28 14:15:20 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-09-28 14:15:20 -0700 |
commit | 29dcd656dfa4c22855b12fb6ee7d6e2e4c4844c1 (patch) | |
tree | f5b4b12f9744d87044cb6424097975a1e1980661 /core/java | |
parent | 8c43650d92ad3b4ec7a13ca83b35a3710fa5a815 (diff) | |
parent | 4e8510b23f6435e8c7631d30ec2ea6f47b16e715 (diff) | |
download | frameworks_base-29dcd656dfa4c22855b12fb6ee7d6e2e4c4844c1.zip frameworks_base-29dcd656dfa4c22855b12fb6ee7d6e2e4c4844c1.tar.gz frameworks_base-29dcd656dfa4c22855b12fb6ee7d6e2e4c4844c1.tar.bz2 |
Merge "Track offset of center child view in Gallery for later layouts" into jb-mr1-dev
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/widget/Gallery.java | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/core/java/android/widget/Gallery.java b/core/java/android/widget/Gallery.java index b72b8cb..e0c5bbd 100644 --- a/core/java/android/widget/Gallery.java +++ b/core/java/android/widget/Gallery.java @@ -182,6 +182,12 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList */ private boolean mIsRtl = true; + /** + * Offset between the center of the selected child view and the center of the Gallery. + * Used to reset position correctly during layout. + */ + private int mSelectedCenterOffset; + public Gallery(Context context) { this(context, null); } @@ -395,6 +401,14 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList setSelectionToCenterChild(); + final View selChild = mSelectedChild; + if (selChild != null) { + final int childLeft = selChild.getLeft(); + final int childCenter = selChild.getWidth() / 2; + final int galleryCenter = getWidth() / 2; + mSelectedCenterOffset = childLeft + childCenter - galleryCenter; + } + onScrollChanged(0, 0, 0, 0); // dummy values, View's implementation does not use these. invalidate(); @@ -537,6 +551,7 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList // We haven't been callbacking during the fling, so do it now super.selectionChanged(); } + mSelectedCenterOffset = 0; invalidate(); } @@ -650,7 +665,8 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList View sel = makeAndAddView(mSelectedPosition, 0, 0, true); // Put the selected child in the center - int selectedOffset = childrenLeft + (childrenWidth / 2) - (sel.getWidth() / 2); + int selectedOffset = childrenLeft + (childrenWidth / 2) - (sel.getWidth() / 2) + + mSelectedCenterOffset; sel.offsetLeftAndRight(selectedOffset); fillToGalleryRight(); |