Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        
                    | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
                            Tags
                            
                        
                          
                          - TextBox
- 웹 서비스
- Redirect
- Eclipse
- 이클립스
- scrollView
- MSsql
- SpringSource Tool Suite
- Web Service
- Java
- javascript
- STS
- 웹뷰
- 컬럼명
- 안드로이드
- Android
- Apache Lucene
- varags
- MS-SQL
- decompiler
- C#
- jsp
- html
- Maven
- Bootstrap
- asp.net
- MANTIS
- 자바스크립트
- 자바
- WebView
                            Archives
                            
                        
                          
                          - Today
- Total
bboks.net™
DP to Pixel, Pixel to DP 본문
/**
 * This method convets dp unit to equivalent device specific value in pixels. 
 * 
 * @param dp A value in dp(Device independent pixels) unit. Which we need to convert into pixels
 * @param context Context to get resources and device specific display metrics
 * @return A float value to represent Pixels equivalent to dp according to device
 */
public static float convertDpToPixel(float dp,Context context){
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float px = dp * (metrics.densityDpi/160f);
    return px;
}
/**
 * This method converts device specific pixels to device independent pixels.
 * 
 * @param px A value in px (pixels) unit. Which we need to convert into db
 * @param context Context to get resources and device specific display metrics
 * @return A float value to represent db equivalent to px value
 */
public static float convertPixelsToDp(float px,Context context){
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float dp = px / (metrics.densityDpi / 160f);
    return dp;
 
}