android.text.DynamicLayout Java Examples

The following examples show how to use android.text.DynamicLayout. 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
Source File: OBScrollingTextLayer.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
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 File: DashSpinner.java    From Dash-Spinner with 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
Source File: TextDrawer.java    From 30-android-libraries-in-30-days with 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 #4
Source File: TextDrawer.java    From UltimateAndroid with 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
Source File: OBScrollingTextLayer.java    From GLEXP-Team-onebillion with Apache License 2.0 4 votes vote down vote up
public DynamicLayout layout()
{
    if (dynLayout == null || !displayObjectsValid)
        makeDisplayObjects(width,0);
    return dynLayout;
}
 
Example #6
Source File: OBScrollingText.java    From GLEXP-Team-onebillion with Apache License 2.0 4 votes vote down vote up
public DynamicLayout layout()
{
    return ((OBScrollingTextLayer)layer).layout();
}
 
Example #7
Source File: LayoutHelper.java    From customview-samples with 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());
}