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


Java TypedValue.COMPLEX_UNIT_PX属性代码示例

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


在下文中一共展示了TypedValue.COMPLEX_UNIT_PX属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: setText

@Override public void setText(@Nullable CharSequence text, BufferType type) {
  EmojiProvider provider = EmojiProvider.getInstance(getContext());
  EmojiParser.CandidateList candidates = provider.getCandidates(text);

  if (scaleEmojis && candidates != null && candidates.allEmojis) {
    int emojis = candidates.size();
    float scale = 1.0f;
    if (emojis <= 8) scale += 0.25f;
    if (emojis <= 6) scale += 0.25f;
    if (emojis <= 4) scale += 0.25f;
    if (emojis <= 2) scale += 0.25f;
    super.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalFontSize * scale);
  } else if (scaleEmojis) {
    super.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalFontSize);
  }

  if (useSystemEmoji()) {
    super.setText(text, type);
    return;
  }

  source = EmojiProvider.getInstance(getContext()).emojify(candidates, text, this);
  setTextEllipsized(source);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:24,代码来源:EmojiTextView.java

示例3: adjustTextSize

private void adjustTextSize(String string) {
    if (!mInitiallized) {
        return;
    }
    int startSize = (int) mMinTextSize;
    int heightLimit = getMeasuredHeight() - getCompoundPaddingBottom()
            - getCompoundPaddingTop();
    mWidthLimit = getMeasuredWidth() - getCompoundPaddingLeft()
            - getCompoundPaddingRight();
    mAvailableSpaceRect.right = mWidthLimit;
    mAvailableSpaceRect.bottom = heightLimit;
    super.setTextSize(
            TypedValue.COMPLEX_UNIT_PX,
            efficientTextSizeSearch(startSize, (int) mMaxTextSize,
                    mSizeTester, mAvailableSpaceRect));
}
 
开发者ID:chashmeetsingh,项目名称:TrackIt-Android,代码行数:16,代码来源:AutoResizeTextView.java

示例4: 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:ifadai,项目名称:AndroidThemeChange,代码行数:26,代码来源:SizeUtils.java

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

示例6: 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

示例7: adjustTextSize

private void adjustTextSize(String string) {
    if (!mInitiallized) {
        return;
    }
    int startSize = (int) mMinTextSize;
    int heightLimit = getMeasuredHeight() - getCompoundPaddingBottom()
            - getCompoundPaddingTop();
    mWidthLimit = getMeasuredWidth() - getCompoundPaddingLeft()
            - getCompoundPaddingRight();
    mAvailableSpaceRect.right = mWidthLimit;
    mAvailableSpaceRect.bottom = heightLimit;
    super.setTextSize(TypedValue.COMPLEX_UNIT_PX,
            efficientTextSizeSearch(startSize,
                    (int) mMaxTextSize,
                    mSizeTester,
                    mAvailableSpaceRect));
}
 
开发者ID:eyeRS,项目名称:eyeRS,代码行数:17,代码来源:AutoResizeTextView.java

示例8: resetTextSize

/**
 * Reset the text to the original size
 */
public void resetTextSize() {
	if (mTextSize > 0) {
		super.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
		mMaxTextSize = mTextSize;
	}
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:9,代码来源:FontFitTextView.java

示例9: resetTextSize

/**
 * Reset the text to the original size
 */
public void resetTextSize() {
    if (mTextSize > 0) {
        super.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
        mMaxTextSize = mTextSize;
    }
}
 
开发者ID:AbduazizKayumov,项目名称:Flashcard-Maker-Android,代码行数:9,代码来源:AutoResizeTextView.java

示例10: PixelValue

public PixelValue(float value, @PixelUnit int unit) {
    if (unit == EM) {
        this.value = value * 16;
        this.unit = TypedValue.COMPLEX_UNIT_PX;
    } else {
        this.value = value;
        this.unit = unit;
    }
}
 
开发者ID:hsllany,项目名称:HtmlNative,代码行数:9,代码来源:PixelValue.java

示例11: 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

示例12: toPixel

@NonNull
public static PixelValue toPixel(@NonNull Object object) throws ParametersParseException {
    int unit = TypedValue.COMPLEX_UNIT_PX;
    if (object instanceof String) {
        String string = (String) object;

        if (string.length() == 0 || (string.equals("@"))) {
            throw new ParametersParseException("wrong when parse pixel");
        }

        if (string.charAt(0) == '@' && string.length() > 1) {
            String resId = string.substring(1);
            Context context = ContextProvider.getApplicationRef();
            if (context != null) {
                float size = ResourceUtils.getDimension(resId, ContextProvider
                        .getApplicationRef());
                return new PixelValue(size);
            } else {
                throw new ParametersParseException("wrong when parse pixel");
            }
        }

        StringBuilder unitString = new StringBuilder(5);
        int i = string.length() - 1;
        for (; i > 0; i--) {
            char c = string.charAt(i);
            if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
                unitString.append(c);
            } else {
                break;
            }
        }

        unit = getUnit(unitString.reverse().toString());

        float value = 0;
        value = toFloat(string.substring(0, i + 1));
        return new PixelValue(value, unit);
    } else {
        return new PixelValue(toFloat(object), unit);
    }

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

示例13: resizeText

/**
 * Resizes this view's text size with respect to its width and height
 * (minus padding).
 */
private void resizeText() {
    final int availableHeightPixels = getHeight() - getCompoundPaddingBottom() - getCompoundPaddingTop();
    final int availableWidthPixels = getWidth() - getCompoundPaddingLeft() - getCompoundPaddingRight();
    final CharSequence text = getText();
    // Safety check
    // (Do not resize if the view does not have dimensions or if there is no text)
    if (text == null
            || text.length() <= 0
            || availableHeightPixels <= 0
            || availableWidthPixels <= 0
            || mMaxTextSizePixels <= 0) {
        return;
    }
    float targetTextSizePixels = mMaxTextSizePixels;
    int targetTextHeightPixels = getTextHeightPixels(text, availableWidthPixels, targetTextSizePixels);
    // Until we either fit within our TextView
    // or we have reached our minimum text size,
    // incrementally try smaller sizes
    while (targetTextHeightPixels > availableHeightPixels
            && targetTextSizePixels > mMinTextSizePixels) {
        targetTextSizePixels = Math.max(
                targetTextSizePixels - 2,
                mMinTextSizePixels);
        targetTextHeightPixels = getTextHeightPixels(
                text,
                availableWidthPixels,
                targetTextSizePixels);
    }
    // If we have reached our minimum text size and the text still doesn't fit,
    // append an ellipsis
    // (NOTE: Auto-ellipsize doesn't work hence why we have to do it here)
    // depending on the value of getEllipsize())
    if (getEllipsize() != null
            && targetTextSizePixels == mMinTextSizePixels
            && targetTextHeightPixels > availableHeightPixels) {
        // Make a copy of the original TextPaint object for measuring
        TextPaint textPaintCopy = new TextPaint(getPaint());
        textPaintCopy.setTextSize(targetTextSizePixels);
        // Measure using a StaticLayout instance
        StaticLayout staticLayout = new StaticLayout(
                text,
                textPaintCopy,
                availableWidthPixels,
                Layout.Alignment.ALIGN_NORMAL,
                mLineSpacingMultiplier,
                mLineSpacingExtra,
                false);
        // Check that we have a least one line of rendered text
        if (staticLayout.getLineCount() > 0) {
            // Since the line at the specific vertical position would be cut off,
            // we must trim up to the previous line and add an ellipsis
            int lastLine = staticLayout.getLineForVertical(availableHeightPixels) - 1;
            if (lastLine >= 0) {
                int startOffset = staticLayout.getLineStart(lastLine);
                int endOffset = staticLayout.getLineEnd(lastLine);
                float lineWidthPixels = staticLayout.getLineWidth(lastLine);
                float ellipseWidth = textPaintCopy.measureText(mEllipsis);
                // Trim characters off until we have enough room to draw the ellipsis
                while (availableWidthPixels < lineWidthPixels + ellipseWidth) {
                    endOffset--;
                    lineWidthPixels = textPaintCopy.measureText(
                            text.subSequence(startOffset, endOffset + 1).toString());
                }
                setText(text.subSequence(0, endOffset) + mEllipsis);
            }
        }
    }
    super.setTextSize(TypedValue.COMPLEX_UNIT_PX, targetTextSizePixels);
    // Some devices try to auto adjust line spacing, so force default line spacing
    super.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
}
 
开发者ID:sega4revenge,项目名称:Sega,代码行数:75,代码来源:AutoResizeTextView.java

示例14: fromPx

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

示例15: toPx

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


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