Develop
2016.10.21 11:16
[android] dp, px 서로 변환
조회 수 3496 댓글 0
# Context가 있는 Activity 내부용 함수
//dp를 px로 변환 (dp를 입력받아 px을 리턴) public float convertDpToPixel(float dp){ Resources resources = this.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); return px; } //px을 dp로 변환 (px을 입력받아 dp를 리턴) public float convertPixelsToDp(float px){ Resources resources = this.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float dp = px / ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); return dp; }
# Context를 변수로 받아서 쓰는 유틸 라이브러리용 Static 함수
//dp를 px로 변환 (dp를 입력받아 px을 리턴) public static float convertDpToPixel(float dp, Context context){ Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); return px; } //px을 dp로 변환 (px을 입력받아 dp를 리턴) public static float convertPixelsToDp(float px, Context context){ Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float dp = px / ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); return dp; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
141 | Develop | [js] Click button copy to clipboard | hooni | 2018.04.05 | 1287 |
140 | Develop | [ios] 코코아 프로그래밍의 네이밍 룰(명명 규칙) | hooni | 2017.05.11 | 1277 |
139 | PPT | [ppt] OCB기술개발팀 OJT 자료 | hooni | 2015.11.13 | 1267 |
138 | Develop | GPL, AGPL, MPL,.. 한눈에 보는 오픈소스SW 라이선스 | hooni | 2014.10.14 | 1259 |
137 | Develop | [ios] Objective-C Types & Storage Capacity | hooni | 2015.07.22 | 1254 |
136 | Develop | [ios] UIView 계층구조 | hooni | 2015.01.03 | 1218 |
135 | Develop | [maven] Mac OS에 메이븐(maven) 설치하기 | hooni | 2015.01.21 | 1216 |
134 | System/OS | 맥에서 포트 확인하고 닫기 (mac) | hooni | 2022.03.22 | 1198 |
133 | Develop | [ios] FlckrFeed Example App (Swift) | hooni | 2016.11.27 | 1197 |
132 | Develop | [ios] 최상위 ViewController 가져오기 | hooni | 2015.10.12 | 1196 |
131 | Develop | [ios] 동영상 플레이어 샘플 (for Local File) | hooni | 2017.02.07 | 1193 |
130 | Etc | RSVP 란? | hooni | 2017.11.22 | 1191 |