Skip to content

Commit cfd0f55

Browse files
committed
Create AutoSizeUtils
1 parent fe98481 commit cfd0f55

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2018 JessYan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package me.jessyan.autosize.utils;
17+
18+
import android.content.Context;
19+
import android.util.TypedValue;
20+
21+
/**
22+
* ================================================
23+
* AndroidAutoSize 常用工具类
24+
* <p>
25+
* Created by JessYan on 2018/8/25 15:24
26+
* <a href="mailto:[email protected]">Contact me</a>
27+
* <a href="https://github.com/JessYanCoding">Follow me</a>
28+
* ================================================
29+
*/
30+
public class AutoSizeUtils {
31+
32+
private AutoSizeUtils() {
33+
throw new IllegalStateException("you can't instantiate me!");
34+
}
35+
36+
public static int dp2px(Context context, float value) {
37+
return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, context.getResources().getDisplayMetrics()) + 0.5f);
38+
}
39+
40+
public static int sp2px(Context context, float value) {
41+
return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, value, context.getResources().getDisplayMetrics()) + 0.5f);
42+
}
43+
}

0 commit comments

Comments
 (0)