本文整理匯總了Java中android.util.TypedValue.COMPLEX_UNIT_IN屬性的典型用法代碼示例。如果您正苦於以下問題:Java TypedValue.COMPLEX_UNIT_IN屬性的具體用法?Java TypedValue.COMPLEX_UNIT_IN怎麽用?Java TypedValue.COMPLEX_UNIT_IN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.util.TypedValue
的用法示例。
在下文中一共展示了TypedValue.COMPLEX_UNIT_IN屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: applyDimension
/**
* 各種單位轉換
* <p>該方法存在於TypedValue</p>
*
* @param unit 單位
* @param value 值
* @param metrics DisplayMetrics
* @return 轉換結果
*/
public static float applyDimension(final int unit, final float value, final DisplayMetrics metrics) {
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
return value;
case TypedValue.COMPLEX_UNIT_DIP:
return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f / 72);
case TypedValue.COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case TypedValue.COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f / 25.4f);
}
return 0;
}
示例2: applyDimension
public static float applyDimension(int unit, float value, DisplayMetrics metrics) {
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
return value;
case TypedValue.COMPLEX_UNIT_DIP:
return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f / 72);
case TypedValue.COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case TypedValue.COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f / 25.4f);
}
return 0;
}
示例3: applyDimension
/**
* 各種單位轉換
* <p>該方法存在於TypedValue</p>
*
* @param unit 單位
* @param value 值
* @param metrics DisplayMetrics
* @return 轉換結果
*/
public static float applyDimension(int unit, float value, DisplayMetrics metrics) {
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
return value;
case TypedValue.COMPLEX_UNIT_DIP:
return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f / 72);
case TypedValue.COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case TypedValue.COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f / 25.4f);
}
return 0;
}
示例4: applyDimension
/**
* 各種單位轉換
* <p>該方法存在於TypedValue
*/
public static float applyDimension(int unit, float value, DisplayMetrics metrics) {
switch (unit) {
case TypedValue.COMPLEX_UNIT_PX:
return value;
case TypedValue.COMPLEX_UNIT_DIP:
return value * metrics.density;
case TypedValue.COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case TypedValue.COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f / 72);
case TypedValue.COMPLEX_UNIT_IN:
return value * metrics.xdpi;
case TypedValue.COMPLEX_UNIT_MM:
return value * metrics.xdpi * (1.0f / 25.4f);
}
return 0;
}
示例5: setDensity
/**
* @param unit {@link TypedValue} Not recommended COMPLEX_UNIT_PX、COMPLEX_UNIT_DIP、COMPLEX_UNIT_SP
* recommend COMPLEX_UNIT_PT
*/
private void setDensity(Context context, int unit) {
if (context != null) {
try {
Resources res = context.getResources();
if ((res.getClass().getSimpleName().contains("MiuiResources") || res.getClass().getSimpleName().contains("XResources")) && !enableOtherResources)
return;
float xdpi = 0f;
DisplayMetrics dm = getMetrics(context.getResources());
if (dm == null) return;
switch (unit) {
case TypedValue.COMPLEX_UNIT_PT:
xdpi = dm.widthPixels / DESIGN_WIDTH * 72;
break;
case TypedValue.COMPLEX_UNIT_IN:
xdpi = dm.widthPixels / DESIGN_WIDTH;
break;
case TypedValue.COMPLEX_UNIT_MM:
xdpi = dm.widthPixels / DESIGN_WIDTH * 25.4f;
break;
case TypedValue.COMPLEX_UNIT_DIP:
xdpi = dm.widthPixels / DESIGN_WIDTH;
break;
}
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putFloat("xdpi", xdpi);
editor.apply();
if (unit == TypedValue.COMPLEX_UNIT_DIP) {
if (enableDp)
dm.density = xdpi;
} else {
dm.xdpi = xdpi;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}