Skip to content

Commit 0e19f70

Browse files
committed
修复圆角属性没有适配 RTL 特性的问题
1 parent 298a495 commit 0e19f70

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

library/src/main/java/com/hjq/shape/builder/ShapeDrawableBuilder.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.hjq.shape.builder;
22

3+
import android.content.Context;
4+
import android.content.res.Configuration;
5+
import android.content.res.Resources;
36
import android.content.res.TypedArray;
47
import android.graphics.Color;
58
import android.graphics.drawable.Drawable;
@@ -102,7 +105,7 @@ public ShapeDrawableBuilder(View view, TypedArray typedArray, IShapeDrawableStyl
102105
mSolidSelectedColor = typedArray.getColor(styleable.getSolidSelectedColorStyleable(), NO_COLOR);
103106
}
104107

105-
int layoutDirection = view.getLayoutDirection();
108+
int layoutDirection = getLayoutDirection(view);
106109

107110
int radius = typedArray.getDimensionPixelSize(styleable.getRadiusStyleable(), 0);
108111
mTopLeftRadius = mTopRightRadius = mBottomLeftRadius = mBottomRightRadius = radius;
@@ -814,6 +817,28 @@ public void intoBackground() {
814817
mView.setBackground(drawable);
815818
}
816819

820+
/**
821+
* 从上下文中获取当前布局方向
822+
*/
823+
private static int getLayoutDirection(View view) {
824+
int layoutDirection;
825+
Context context = view.getContext();
826+
Resources resources = null;
827+
Configuration configuration = null;
828+
if (context != null) {
829+
resources = context.getResources();
830+
}
831+
if (resources != null) {
832+
configuration = resources.getConfiguration();
833+
}
834+
if (configuration != null) {
835+
layoutDirection = configuration.getLayoutDirection();
836+
} else {
837+
layoutDirection = View.LAYOUT_DIRECTION_LTR;
838+
}
839+
return layoutDirection;
840+
}
841+
817842
/**
818843
* 将 ShapeView 框架中渐变色的 xml 属性值转换成 ShapeDrawable 中的枚举值
819844
*/

0 commit comments

Comments
 (0)