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


Java TransformationMethod.getTransformation方法代码示例

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


在下文中一共展示了TransformationMethod.getTransformation方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: refitText

import android.text.method.TransformationMethod; //导入方法依赖的package包/类
/**
 * Re size the font so the specified text fits in the text box assuming the text box is the
 * specified width.
 */
private void refitText() {
    CharSequence text = getText();

    if (TextUtils.isEmpty(text)) {
        return;
    }

    TransformationMethod method = getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, this);
    }
    int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
    if (targetWidth > 0) {
        float high = 100;
        float low = 0;

        mPaint.set(getPaint());
        mPaint.setTextSize(getTextSize());
        float letterSpacing = getLetterSpacing(text, mPaint, targetWidth, low, high,
                mPrecision);
        mPaint.setLetterSpacing(letterSpacing);
        calculateSections(text);

        super.setLetterSpacing(letterSpacing);
    }
}
 
开发者ID:talentlo,项目名称:Trebuchet,代码行数:31,代码来源:AutoExpandTextView.java

示例2: autofit

import android.text.method.TransformationMethod; //导入方法依赖的package包/类
/**
    * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
    */
   private static void autofit(AppCompatTextView view, TextPaint paint, float minTextSize, float maxTextSize,
							int maxLines, float precision)
{
       if (maxLines <= 0 || maxLines == Integer.MAX_VALUE)
	{
           // Don't auto-size since there's no limit on lines.
           return;
       }

       int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
       if (targetWidth <= 0)
	{
           return;
       }

       CharSequence text = view.getText();
       TransformationMethod method = view.getTransformationMethod();
       if (method != null)
	{
           text = method.getTransformation(text, view);
       }

       Context context = view.getContext();
       Resources r = Resources.getSystem();
       DisplayMetrics displayMetrics;

       float size = maxTextSize;
       float high = size;
       float low = 0;

       if (context != null)
	{
           r = context.getResources();
       }
       displayMetrics = r.getDisplayMetrics();

       paint.set(view.getPaint());
       paint.setTextSize(size);

       if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
		|| getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines)
	{
           size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
								  displayMetrics);
       }

       if (size < minTextSize)
	{
           size = minTextSize;
       }

       view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
   }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:57,代码来源:AutofitHelper.java

示例3: autofit

import android.text.method.TransformationMethod; //导入方法依赖的package包/类
/**
 * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
 */
private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
                            int maxLines, float precision) {
    if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
    if (targetWidth <= 0) {
        return;
    }

    CharSequence text = view.getText();
    TransformationMethod method = view.getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, view);
    }

    Context context = view.getContext();
    Resources r = Resources.getSystem();
    DisplayMetrics displayMetrics;

    float size = maxTextSize;
    float high = size;
    float low = 0;

    if (context != null) {
        r = context.getResources();
    }
    displayMetrics = r.getDisplayMetrics();

    paint.set(view.getPaint());
    paint.setTextSize(size);

    if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
            || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
        size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
                displayMetrics);
    }

    if (size < minTextSize) {
        size = minTextSize;
    }

    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
 
开发者ID:victorminerva,项目名称:AutoResizeEditText,代码行数:50,代码来源:AutofitHelper.java

示例4: adjustTextSize

import android.text.method.TransformationMethod; //导入方法依赖的package包/类
/**
 * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
 */
private static void adjustTextSize(TextView view, TextPaint paint, float minTextSize, float maxTextSize, int maxLines, float precision) {
    if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
    if (targetWidth <= 0) {
        return;
    }

    CharSequence text = view.getText();
    TransformationMethod method = view.getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, view);
    }

    Context context = view.getContext();
    Resources r = Resources.getSystem();
    DisplayMetrics displayMetrics;

    float size = maxTextSize;
    float high = size;
    float low = 0;

    if (context != null) {
        r = context.getResources();
    }
    displayMetrics = r.getDisplayMetrics();

    paint.set(view.getPaint());
    paint.setTextSize(size);

    if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
            || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
        size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision, displayMetrics);
    }

    if (size < minTextSize) {
        size = minTextSize;
    }

    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:48,代码来源:TextUtil.java

示例5: autofit

import android.text.method.TransformationMethod; //导入方法依赖的package包/类
/**
 * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
 */
private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
        int maxLines, float precision) {
    if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
    if (targetWidth <= 0) {
        return;
    }

    CharSequence text = view.getText();
    TransformationMethod method = view.getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, view);
    }

    Context context = view.getContext();
    Resources r = Resources.getSystem();
    DisplayMetrics displayMetrics;

    float size = maxTextSize;
    float high = size;
    float low = 0;

    if (context != null) {
        r = context.getResources();
    }
    displayMetrics = r.getDisplayMetrics();

    paint.set(view.getPaint());
    paint.setTextSize(size);

    if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
            || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
        size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
                displayMetrics);
    }

    if (size < minTextSize) {
        size = minTextSize;
    }

    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
 
开发者ID:WrapOnly,项目名称:android-autofittextview,代码行数:50,代码来源:AutofitHelper.java

示例6: autofit

import android.text.method.TransformationMethod; //导入方法依赖的package包/类
/**
 * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
 */
private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
        int maxLines, float precision) {
    if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
    if (targetWidth <= 0) {
        return;
    }

    CharSequence text = view.getText();
    TransformationMethod method = view.getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, view);
    }

    Context context = view.getContext();
    Resources r = Resources.getSystem();
    DisplayMetrics displayMetrics;

    float size = maxTextSize;
    float high = size;
    float low = 0;

    if (context != null) {
        r = context.getResources();
    }
    displayMetrics = r.getDisplayMetrics();

    paint.set(view.getPaint());
    paint.setTextSize(size);

    if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
            || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
        size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
                displayMetrics);
    }

    if (mIsHeightFitting) {
        int targetHeight = view.getHeight() - view.getPaddingTop() - view.getPaddingTop();
        if (targetHeight <= 0) {
            if (size < minTextSize) {
                size = minTextSize;
            }
            view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
            return;
        }

        float textHeight = getTextHeight(text, paint, targetWidth, size);
        textHeight = getTextHeight(text, paint, targetWidth, size);
        float heightRatio = targetHeight / textHeight;
        float newSize = size * heightRatio;
        if (newSize < size) {
            size = newSize;
        }

        if (size < minTextSize) {
            size = minTextSize;
        }
    }

    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
 
开发者ID:KonradJanica,项目名称:aMatch,代码行数:69,代码来源:AutofitHelper.java

示例7: refitText

import android.text.method.TransformationMethod; //导入方法依赖的package包/类
/**
 * Re size the font so the specified text fits in the text box assuming the text box is the
 * specified width.
 */
private void refitText() {
    if (!mSizeToFit) {
        return;
    }

    if (mMaxLines <= 0) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    CharSequence text = getText();
    TransformationMethod method = getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, this);
    }
    int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
    if (targetWidth > 0) {
        Context context = getContext();
        Resources r = Resources.getSystem();
        DisplayMetrics displayMetrics;

        float size = mMaxTextSize;
        float high = size;
        float low = 0;

        if (context != null) {
            r = context.getResources();
        }
        displayMetrics = r.getDisplayMetrics();

        mPaint.set(getPaint());
        mPaint.setTextSize(size);

        if ((mMaxLines == 1 && mPaint.measureText(text, 0, text.length()) > targetWidth)
                || getLineCount(text, mPaint, size, targetWidth, displayMetrics) > mMaxLines) {
            size = getTextSize(text, mPaint, targetWidth, mMaxLines, low, high, mPrecision,
                    displayMetrics);
        }

        if (size < mMinTextSize) {
            size = mMinTextSize;
        }

        super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
    }
}
 
开发者ID:cymcsg,项目名称:UltimateAndroid,代码行数:51,代码来源:AutofitTextView.java


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