當前位置: 首頁>>代碼示例>>Java>>正文


Java DisplayMetrics.DENSITY_DEFAULT屬性代碼示例

本文整理匯總了Java中android.util.DisplayMetrics.DENSITY_DEFAULT屬性的典型用法代碼示例。如果您正苦於以下問題:Java DisplayMetrics.DENSITY_DEFAULT屬性的具體用法?Java DisplayMetrics.DENSITY_DEFAULT怎麽用?Java DisplayMetrics.DENSITY_DEFAULT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.util.DisplayMetrics的用法示例。


在下文中一共展示了DisplayMetrics.DENSITY_DEFAULT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getScreenType

private static int getScreenType(Context con) {
    if (mDeviceType == -1) {
        WindowManager wm = (WindowManager) con.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(outMetrics);
        int shortSize = Math.min(outMetrics.heightPixels, outMetrics.widthPixels);
        int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / outMetrics.densityDpi;
        if (shortSizeDp < 600) {
            // 0-599dp: "phone" UI with a separate status & navigation bar
            mDeviceType = DEVICE_PHONE;
        } else if (shortSizeDp < 720) {
            // 600-719dp: "phone" UI with modifications for larger screens
            mDeviceType = DEVICE_HYBRID;
        } else {
            // 720dp: "tablet" UI with a single combined status & navigation bar
            mDeviceType = DEVICE_TABLET;
        }
    }
    return mDeviceType;
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:20,代碼來源:Utils.java

示例2: CrumbView

public CrumbView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    defaultPaint.setColor(fetchDefaultColour());

    int densityRatio = getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT;
    dotInterval = 16 * densityRatio;
    dotRadius = 4 * densityRatio;
}
 
開發者ID:Deliganli,項目名稱:crumber,代碼行數:9,代碼來源:CrumbView.java

示例3: temporaryRestoreDefaultDensity

/**
 * restores normal density without saving it for next start
 */
public void temporaryRestoreDefaultDensity(){
    Resources res = mActivity.getResources();
    DisplayMetrics displayMetrics = res.getDisplayMetrics();
    Configuration config = res.getConfiguration();
    displayMetrics.densityDpi = DisplayMetrics.DENSITY_DEFAULT;
    config.densityDpi = Configuration.DENSITY_DPI_UNDEFINED;
    res.updateConfiguration(config, displayMetrics);
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:11,代碼來源:DensityTweak.java

示例4: dpToPx

public static int dpToPx(int dp) {
  DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
  return  dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
 
開發者ID:saveendhiman,項目名稱:FacebookReaction,代碼行數:4,代碼來源:DisplayUtil.java

示例5: convertPixelsToDp

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;
}
 
開發者ID:adonixis,項目名稱:android-submit-credit-card-flow,代碼行數:6,代碼來源:SubmitCreditCardActivity.java

示例6: convertDpToPixel

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;
}
 
開發者ID:anikraj1994,項目名稱:Remote,代碼行數:6,代碼來源:ViewMetrics.java

示例7: convertPixelsToDp

private int convertPixelsToDp(int px) {
    return px / (mDisplayMetrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
 
開發者ID:R12rus,項目名稱:ShadowFrameLayout,代碼行數:3,代碼來源:ShadowFrameLayout.java

示例8: convertDpToPixel

public static int convertDpToPixel(float dp, Context context) {
  Resources resources = context.getResources();
  DisplayMetrics metrics = resources.getDisplayMetrics();
  return (int) (dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT));
}
 
開發者ID:DevAhamed,項目名稱:MultiViewAdapter,代碼行數:5,代碼來源:DragAndDropActivity.java

示例9: ConvertTopx

private int ConvertTopx(float dp) {
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    return ((int) (dp * ((float) metrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT));

}
 
開發者ID:coder3101,項目名稱:Matrix-Calculator-for-Android,代碼行數:5,代碼來源:FillingMatrix.java

示例10: dpiFromPx

public static float dpiFromPx(int size, DisplayMetrics metrics){
    float densityRatio = (float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT;
    return (size / densityRatio);
}
 
開發者ID:TeamBrainStorm,項目名稱:SimpleUILauncher,代碼行數:4,代碼來源:Utilities.java

示例11: FromDpToPixels

public static float FromDpToPixels(float dp, Context context) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    return dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
 
開發者ID:humaniq,項目名稱:humaniq-android,代碼行數:5,代碼來源:GraphicKeyView.java

示例12: convertDpToPixel

public static float convertDpToPixel(float dp, Context context){
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    return dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
 
開發者ID:lurbas,項目名稱:MaterialMasterDetail,代碼行數:5,代碼來源:ViewUtils.java

示例13: getPixelScaleFactor

private static float getPixelScaleFactor(Context context) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    return (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT);
}
 
開發者ID:chenzj-king,項目名稱:RetrofitSample,代碼行數:4,代碼來源:PixelUtil.java

示例14: convertPixelsToDp

/**
 * This method converts device specific pixels to density 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 dp equivalent to px value
 */
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;
}
 
開發者ID:Bruno125,項目名稱:Unofficial-Ups,代碼行數:13,代碼來源:UiUtils.java

示例15: convertDpToPixel

/**
 * This method converts dp unit to equivalent pixels, depending on device density.
 *
 * @param dp      A value in dp (density 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 px equivalent to dp depending on device density
 */
private 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;
}
 
開發者ID:GeorgeArgyrakis,項目名稱:FloatingKeyboard,代碼行數:13,代碼來源:FloatingKeyboardView.java


注:本文中的android.util.DisplayMetrics.DENSITY_DEFAULT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。