Skip to content

Commit

Permalink
修复预览显示的问题,更新README,祝大家新年快乐,新的一年事业有成
Browse files Browse the repository at this point in the history
  • Loading branch information
Brook007 committed Feb 4, 2019
1 parent 14d5e18 commit e5af50d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ allprojects {
然后在需要使用的模块的build.gradle中添加以下代码
```groovy
dependencies {
implementation 'com.github.Brook007:DependencyLayout:1.0.1'
implementation 'com.github.Brook007:DependencyLayout:1.0.3'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public static float dp2px(float dpVal) {
* @param spVal
* @return
*/
public static int sp2px(float spVal) {
public static float sp2px(float spVal) {
final float fontScale = getContext().getResources().getDisplayMetrics().scaledDensity;
return (int) (spVal * fontScale + 0.5f);
return (spVal * fontScale + 0.5f);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -942,13 +942,16 @@ public LayoutParams(Context context, AttributeSet attrs) {
private float calculationSystem(TypedArray typedArray, int attr, DisplayMetrics displayMetrics) {
String text = Util.getText(typedArray, attr);
String value = Util.getValue(text);
String unit = text.substring(value.length(), text.length()).toLowerCase();
if ("dip".equals(unit)) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Float.valueOf(value), displayMetrics);
String unit = text.substring(value.length()).toLowerCase();
if ("dip".equals(unit) || "dp".equals(unit)) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Util.toFloat(value), displayMetrics);
} else if ("px".endsWith(unit)) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, Float.valueOf(value), displayMetrics);
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, Util.toFloat(value), displayMetrics);
} else if ("sp".endsWith(unit)) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, Util.toFloat(value), displayMetrics);
} else {
return Util.toFloat(value);
}
return Float.valueOf(value);
}

/**
Expand Down

0 comments on commit e5af50d

Please sign in to comment.