From e5af50d5f57757dbd3b2b53a8d7525f8fdd79740 Mon Sep 17 00:00:00 2001 From: Brook007 <875428190@qq.com> Date: Tue, 5 Feb 2019 00:37:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A2=84=E8=A7=88=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?README=EF=BC=8C=E7=A5=9D=E5=A4=A7=E5=AE=B6=E6=96=B0=E5=B9=B4?= =?UTF-8?q?=E5=BF=AB=E4=B9=90=EF=BC=8C=E6=96=B0=E7=9A=84=E4=B8=80=E5=B9=B4?= =?UTF-8?q?=E4=BA=8B=E4=B8=9A=E6=9C=89=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../brook/app/android/supportlibrary/util/Util.java | 4 ++-- .../supportlibrary/view/DependencyLayout.java | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 420881c..37fe01b 100644 --- a/README.md +++ b/README.md @@ -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' } ``` diff --git a/library/src/main/java/com/brook/app/android/supportlibrary/util/Util.java b/library/src/main/java/com/brook/app/android/supportlibrary/util/Util.java index 4d964e8..ccf2156 100644 --- a/library/src/main/java/com/brook/app/android/supportlibrary/util/Util.java +++ b/library/src/main/java/com/brook/app/android/supportlibrary/util/Util.java @@ -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); } } diff --git a/library/src/main/java/com/brook/app/android/supportlibrary/view/DependencyLayout.java b/library/src/main/java/com/brook/app/android/supportlibrary/view/DependencyLayout.java index e59aaa6..a9db13f 100644 --- a/library/src/main/java/com/brook/app/android/supportlibrary/view/DependencyLayout.java +++ b/library/src/main/java/com/brook/app/android/supportlibrary/view/DependencyLayout.java @@ -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); } /**