当前位置: 首页>>代码示例>>Java>>正文


Java TypedValue.COMPLEX_UNIT_DIP属性代码示例

本文整理汇总了Java中android.util.TypedValue.COMPLEX_UNIT_DIP属性的典型用法代码示例。如果您正苦于以下问题:Java TypedValue.COMPLEX_UNIT_DIP属性的具体用法?Java TypedValue.COMPLEX_UNIT_DIP怎么用?Java TypedValue.COMPLEX_UNIT_DIP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.util.TypedValue的用法示例。


在下文中一共展示了TypedValue.COMPLEX_UNIT_DIP属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:SizeUtils.java

示例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;
}
 
开发者ID:ChangsenLai,项目名称:codedemos,代码行数:17,代码来源:SizeUtils.java

示例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;
}
 
开发者ID:hoangkien0705,项目名称:Android-UtilCode,代码行数:26,代码来源:SizeUtils.java

示例4: getUnit

@PixelValue.PixelUnit
private static int getUnit(String s) throws ParametersParseException {
    switch (s.toLowerCase()) {
        default:
            throw new ParametersParseException("Unknown unit " + s);
        case "px":
            return TypedValue.COMPLEX_UNIT_PX;
        case "dp":
        case "dip":
            return TypedValue.COMPLEX_UNIT_DIP;
        case "sp":
            return TypedValue.COMPLEX_UNIT_SP;
        case "em":
            return PixelValue.EM;

    }
}
 
开发者ID:hsllany,项目名称:HtmlNative,代码行数:17,代码来源:ParametersUtils.java

示例5: getPxValue

public final float getPxValue() {
    switch (unit) {
        case EM:
            return this.value / 16.f;
        case TypedValue.COMPLEX_UNIT_PX:
            return this.value;
        case TypedValue.COMPLEX_UNIT_SP:
            return ParametersUtils.spToPx(this.value);
        case TypedValue.COMPLEX_UNIT_DIP:
            return ParametersUtils.dpToPx(this.value);
        default:
            return value;
    }
}
 
开发者ID:hsllany,项目名称:HtmlNative,代码行数:14,代码来源:PixelValue.java

示例6: 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();
        }
    }
}
 
开发者ID:hjhrq1991,项目名称:screenAdaptation,代码行数:41,代码来源:ScreenAdaperHelper.java

示例7: dpToPx

/**
 * Another way to convert dp(density-independent pixels) unit to equivalent px(pixels),
 * depending on device {@link DisplayMetrics}, using {@link TypedValue}.
 * This method is more recommended compared to {@link #convertDpToPx(float, Context)}.
 *
 * @param dp      value in dp unit which will be converted into px
 * @param context context to get resources and device specific display metrics
 * @return a float value to represent px equivalent to dp
 */
public synchronized static float dpToPx(float dp, Context context) {
    final Resources resources = context.getResources();
    final DisplayMetrics metrics = resources.getDisplayMetrics();
    final int unit = TypedValue.COMPLEX_UNIT_DIP;
    return TypedValue.applyDimension(unit, dp, metrics);
}
 
开发者ID:HotBitmapGG,项目名称:Acg,代码行数:15,代码来源:DisplayUtil.java

示例8: fromDp

public Builder fromDp(float fromSize) { unit = TypedValue.COMPLEX_UNIT_DIP; return from(fromSize); } 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:1,代码来源:WoWoTextViewTextSizeAnimation.java

示例9: toDp

public Builder toDp(float toSize) { unit = TypedValue.COMPLEX_UNIT_DIP; return to(toSize); } 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:1,代码来源:WoWoTextViewTextSizeAnimation.java


注:本文中的android.util.TypedValue.COMPLEX_UNIT_DIP属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。