Skip to content

Commit

Permalink
Set margin correctly for the right to left layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey Ushakov committed Mar 17, 2020
1 parent 656cd3b commit 222f3ae
Showing 1 changed file with 17 additions and 1 deletion.
Expand Up @@ -3,10 +3,12 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutCompat;
import android.util.AttributeSet;
Expand Down Expand Up @@ -135,7 +137,11 @@ protected FrameLayout createBoxedItem(final int position) {
(int) (mItemSize * mItemScale)
);
if (position > 0) {
boxParams.setMargins(mDelimiterSize, 0, 0, 0);
if (isRtl()) {
boxParams.setMargins(0, 0, mDelimiterSize, 0);
} else {
boxParams.setMargins(mDelimiterSize, 0, 0, 0);
}
}
box.setLayoutParams(boxParams);
return box;
Expand All @@ -153,6 +159,16 @@ protected ImageView createItem() {
return index;
}

private boolean isRtl() {
final boolean result;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
result = getContext().getResources().getConfiguration().getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL;
} else {
result = false;
}
return result;
}

protected class OnPageChangeListener implements ViewPager.OnPageChangeListener {

@Override
Expand Down

0 comments on commit 222f3ae

Please sign in to comment.