Java Code Examples for android.text.DynamicLayout

The following examples show how to use android.text.DynamicLayout. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void makeDisplayObjects(float maxw,int just)
{
    textPaint.setTextSize(textSize);
    textPaint.setTypeface(typeFace);
    textPaint.setColor(colour);
    dynLayout = new DynamicLayout(textBuffer(),textPaint,(int)width, Layout.Alignment.ALIGN_NORMAL,1,0,true);
    displayObjectsValid = true;
}
 
Example 2
Source Project: Dash-Spinner   Source File: DashSpinner.java    License: MIT License 5 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
	super.onSizeChanged(w, h, oldw, oldh);

	// Initialize the values;
	initializeValues();

	// Build a new Dynamic Layout with the available width since we can only provide width when the dynamic layout is created
	mDynamicLayout = new DynamicLayout(mStringBuilder, mStringBuilder, mTextPaint, w, Layout.Alignment.ALIGN_CENTER, 1.0f, 1.0f, true);
}
 
Example 3
public void draw(Canvas canvas) {
    if (shouldDrawText()) {
        float[] textPosition = getBestTextPosition();

        if (!TextUtils.isEmpty(mTitle)) {
            canvas.save();
            if (hasRecalculated) {
                mDynamicTitleLayout = new DynamicLayout(mTitle, titlePaint,
                        (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL,
                        1.0f, 1.0f, true);
            }
            if (mDynamicTitleLayout != null) {
                canvas.translate(textPosition[0], textPosition[1]);
                mDynamicTitleLayout.draw(canvas);
                canvas.restore();
            }
        }

        if (!TextUtils.isEmpty(mDetails)) {
            canvas.save();
            if (hasRecalculated) {
                mDynamicDetailLayout = new DynamicLayout(mDetails, textPaint,
                        (int) textPosition[2],
                        Layout.Alignment.ALIGN_NORMAL,
                        1.2f, 1.0f, true);
            }
            float offsetForTitle = mDynamicTitleLayout != null ? mDynamicTitleLayout.getHeight() :
                    0;
            if (mDynamicDetailLayout != null) {
                canvas.translate(textPosition[0], textPosition[1] + offsetForTitle);
                mDynamicDetailLayout.draw(canvas);
                canvas.restore();
            }

        }
    }
    hasRecalculated = false;
}
 
Example 4
Source Project: UltimateAndroid   Source File: TextDrawer.java    License: Apache License 2.0 5 votes vote down vote up
public void draw(Canvas canvas) {
    if (shouldDrawText()) {
        float[] textPosition = getBestTextPosition();

        if (!TextUtils.isEmpty(mTitle)) {
            canvas.save();
            if (hasRecalculated) {
                mDynamicTitleLayout = new DynamicLayout(mTitle, titlePaint,
                        (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL,
                        1.0f, 1.0f, true);
            }
            if (mDynamicTitleLayout != null) {
                canvas.translate(textPosition[0], textPosition[1]);
                mDynamicTitleLayout.draw(canvas);
                canvas.restore();
            }
        }

        if (!TextUtils.isEmpty(mDetails)) {
            canvas.save();
            if (hasRecalculated) {
                mDynamicDetailLayout = new DynamicLayout(mDetails, textPaint,
                        (int) textPosition[2],
                        Layout.Alignment.ALIGN_NORMAL,
                        1.2f, 1.0f, true);
            }
            float offsetForTitle = mDynamicTitleLayout != null ? mDynamicTitleLayout.getHeight() :
                    0;
            if (mDynamicDetailLayout != null) {
                canvas.translate(textPosition[0], textPosition[1] + offsetForTitle);
                mDynamicDetailLayout.draw(canvas);
                canvas.restore();
            }

        }
    }
    hasRecalculated = false;
}
 
Example 5
public DynamicLayout layout()
{
    if (dynLayout == null || !displayObjectsValid)
        makeDisplayObjects(width,0);
    return dynLayout;
}
 
Example 6
Source Project: GLEXP-Team-onebillion   Source File: OBScrollingText.java    License: Apache License 2.0 4 votes vote down vote up
public DynamicLayout layout()
{
    return ((OBScrollingTextLayer)layer).layout();
}
 
Example 7
Source Project: customview-samples   Source File: LayoutHelper.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 这里构建一个Layout,用于辅助计算,不是TextView关联的Layout
 * @param text
 * @return
 */
protected Layout buildCalculateLayout(CharSequence text){
    TextPaint paint = copyPaint();
    return new DynamicLayout(text,paint, mLayoutWidth,mHost.getLayout().getAlignment(),mHost.getLayout().getSpacingMultiplier(),mHost.getLayout().getSpacingAdd(),mHost.getIncludeFontPadding());
}