Fix dividers position for LinearLayout

- see bug #5429822 UI should be mirrored for RTL locales (Arabic, Hebrew, farsi)

Change-Id: I81a294966ec3989785c0b55d2e4d418ddc89fadd
This commit is contained in:
Fabrice Di Meglio
2012-07-02 19:12:40 -07:00
parent 3a4832aa64
commit 4ab6968bb7

View File

@@ -345,28 +345,42 @@ public class LinearLayout extends ViewGroup {
void drawDividersHorizontal(Canvas canvas) {
final int count = getVirtualChildCount();
final boolean isLayoutRtl = isLayoutRtl();
for (int i = 0; i < count; i++) {
final View child = getVirtualChildAt(i);
if (child != null && child.getVisibility() != GONE) {
if (hasDividerBeforeChildAt(i)) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int left = child.getLeft() - lp.leftMargin - mDividerWidth;
drawVerticalDivider(canvas, left);
final int position;
if (isLayoutRtl) {
position = child.getRight() + lp.rightMargin;
} else {
position = child.getLeft() - lp.leftMargin - mDividerWidth;
}
drawVerticalDivider(canvas, position);
}
}
}
if (hasDividerBeforeChildAt(count)) {
final View child = getVirtualChildAt(count - 1);
int right = 0;
int position;
if (child == null) {
right = getWidth() - getPaddingRight() - mDividerWidth;
if (isLayoutRtl) {
position = getPaddingLeft();
} else {
position = getWidth() - getPaddingRight() - mDividerWidth;
}
} else {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
right = child.getRight() + lp.rightMargin;
if (isLayoutRtl) {
position = child.getLeft() - lp.leftMargin - mDividerWidth;
} else {
position = child.getRight() + lp.rightMargin;
}
}
drawVerticalDivider(canvas, right);
drawVerticalDivider(canvas, position);
}
}