Develop
2016.10.21 11:16
[android] dp, px 서로 변환
조회 수 3373 댓글 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; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1041 | System/OS | Enable the Develop Menu in Safari | hooni | 2017.02.07 | 1069 |
1040 | Develop | [ios] 동영상 플레이어 샘플 (for Local File) | hooni | 2017.02.07 | 1070 |
1039 | Develop | [ios] FlckrFeed Example App (Swift) | hooni | 2016.11.27 | 1072 |
1038 | PPT | [ppt] 정보보호관리 발표내용 | hooni | 2016.11.30 | 1072 |
1037 | Etc | 영어. 반드시 외워야 할 문장 패턴 100개 | hooni | 2023.06.08 | 1077 |
1036 | Develop | [js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식) | hooni | 2017.12.14 | 1102 |
1035 | Develop | [maven] Mac OS에 메이븐(maven) 설치하기 | hooni | 2015.01.21 | 1106 |
1034 | Develop | [ios] UIView 계층구조 | hooni | 2015.01.03 | 1124 |
1033 | Develop | [coding] Find all anagrams in a string | hooni | 2017.06.27 | 1138 |
1032 | Develop | macOS에 node, npm 설치하기 (homebrew) | hooni | 2021.11.06 | 1139 |
1031 | System/OS | Enable Safari Hidden Debug Menu in Mac OS X | hooni | 2017.02.07 | 1142 |
1030 | Develop | GPL, AGPL, MPL,.. 한눈에 보는 오픈소스SW 라이선스 | hooni | 2014.10.14 | 1146 |