diff options
| author | Fabrice Di Meglio <fdimeglio@google.com> | 2012-06-08 15:22:20 -0700 |
|---|---|---|
| committer | Fabrice Di Meglio <fdimeglio@google.com> | 2012-06-08 15:22:20 -0700 |
| commit | a598720ad6ae21a07aaae50c9469dc3799c3fc30 (patch) | |
| tree | a7f0be6bbf8951ee3f3de77aac4a6651651c7d8b /core/java/android/widget/GridView.java | |
| parent | b4946343e8027925a92f1353af5ad154a84e425f (diff) | |
Make GridView widget aware of layout direction
- see bug #5429822 UI should be mirrored for RTL locales (Arabic, Hebrew, farsi)
Change-Id: Id9ac26028c176e429a7f3ad76c0a428613e1afc8
Diffstat (limited to 'core/java/android/widget/GridView.java')
| -rw-r--r-- | core/java/android/widget/GridView.java | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java index 897510940721..71ad148591a1 100644 --- a/core/java/android/widget/GridView.java +++ b/core/java/android/widget/GridView.java @@ -94,7 +94,7 @@ public class GridView extends AbsListView { private View mReferenceView = null; private View mReferenceViewInSelectedRow = null; - private int mGravity = Gravity.LEFT; + private int mGravity = Gravity.START; private final Rect mTempRect = new Rect(); @@ -300,9 +300,18 @@ public class GridView extends AbsListView { final int columnWidth = mColumnWidth; final int horizontalSpacing = mHorizontalSpacing; + final boolean isLayoutRtl = isLayoutRtl(); + int last; - int nextLeft = mListPadding.left + - ((mStretchMode == STRETCH_SPACING_UNIFORM) ? horizontalSpacing : 0); + int nextLeft; + + if (isLayoutRtl) { + nextLeft = getWidth() - mListPadding.right - columnWidth - + ((mStretchMode == STRETCH_SPACING_UNIFORM) ? horizontalSpacing : 0); + } else { + nextLeft = mListPadding.left + + ((mStretchMode == STRETCH_SPACING_UNIFORM) ? horizontalSpacing : 0); + } if (!mStackFromBottom) { last = Math.min(startPos + mNumColumns, mItemCount); @@ -311,7 +320,8 @@ public class GridView extends AbsListView { startPos = Math.max(0, startPos - mNumColumns + 1); if (last - startPos < mNumColumns) { - nextLeft += (mNumColumns - (last - startPos)) * (columnWidth + horizontalSpacing); + final int deltaLeft = (mNumColumns - (last - startPos)) * (columnWidth + horizontalSpacing); + nextLeft += (isLayoutRtl ? -1 : +1) * deltaLeft; } } @@ -330,7 +340,7 @@ public class GridView extends AbsListView { final int where = flow ? -1 : pos - startPos; child = makeAndAddView(pos, y, flow, nextLeft, selected, where); - nextLeft += columnWidth; + nextLeft += (isLayoutRtl ? -1 : +1) * columnWidth; if (pos < last - 1) { nextLeft += horizontalSpacing; } |
