當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。