Java Code Examples for android.widget.TextView#layout()

The following examples show how to use android.widget.TextView#layout() . 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
@NonNull
private BitmapDescriptor createClusterIcon(int clusterBucket) {
    @SuppressLint("InflateParams")
    TextView clusterIconView = (TextView) LayoutInflater.from(mContext)
            .inflate(R.layout.map_cluster_icon, null);
    clusterIconView.setBackground(createClusterBackground());
    clusterIconView.setTextColor(mIconStyle.getClusterTextColor());
    clusterIconView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
            mIconStyle.getClusterTextSize());

    clusterIconView.setText(getClusterIconText(clusterBucket));

    clusterIconView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    clusterIconView.layout(0, 0, clusterIconView.getMeasuredWidth(),
            clusterIconView.getMeasuredHeight());

    Bitmap iconBitmap = Bitmap.createBitmap(clusterIconView.getMeasuredWidth(),
            clusterIconView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(iconBitmap);
    clusterIconView.draw(canvas);

    return BitmapDescriptorFactory.fromBitmap(iconBitmap);
}
 
Example 2
Source Project: Onosendai   File: ColumnTitleStrip.java    License: Apache License 2.0 6 votes vote down vote up
void updateTextPositions (final int position, final float positionOffset, final boolean force) {
	if (position != this.mLastKnownCurrentPage) {
		updateText(position);
	}
	else if (!force && positionOffset == this.mLastKnownPositionOffset) {
		return;
	}
	this.mUpdatingPositions = true;

	// XXX Use pager's width.
	final int contentWidth = this.pager.getWidth() - getPaddingLeft() - getPaddingRight();
	final int columnWidth = (int) (contentWidth * this.relativePageWidth); // FIXME rounding error may be introduced.
	final int firstColumnLeft = 0 - (columnWidth * position) - getLeft(); // XXX Offset Left.

	for (int i = 0; i < this.labels.size(); i++) {
		final TextView tv = this.labels.get(i);
		final int tLeft = firstColumnLeft + (columnWidth * i) - (int) (positionOffset * columnWidth);
		final int bottomGravTop = getHeight() - getPaddingBottom() - tv.getMeasuredHeight();
		tv.layout(tLeft, bottomGravTop, tLeft + columnWidth, bottomGravTop + tv.getMeasuredHeight());
	}

	this.mLastKnownPositionOffset = positionOffset;
	this.mUpdatingPositions = false;
}
 
Example 3
Source Project: animation-samples   File: TextResize.java    License: Apache License 2.0 5 votes vote down vote up
private static void setTextViewData(TextView view, TextResizeData data, float fontSize) {
    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
    view.setPadding(data.paddingLeft, data.paddingTop, data.paddingRight, data.paddingBottom);
    view.setRight(view.getLeft() + data.width);
    view.setBottom(view.getTop() + data.height);
    view.setTextColor(data.textColor);
    int widthSpec = View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(view.getHeight(), View.MeasureSpec.EXACTLY);
    view.measure(widthSpec, heightSpec);
    view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
}
 
Example 4
Source Project: WidgetCase   File: CustomScrollView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int top = 0;
    for (int i = 0; i < MOCK_ITEM_COUNT; i++) {
        int width = mScreenW;
        int height = mScreenH / 2;
        int left = 0;
        int right = left + width;
        int bottom = top + height;

        // 计算控件实际宽高
        if (bottom > mHeight) {
            mHeight = bottom;
        }
        if (right > mWidth) {
            mWidth = right;
        }

        // 生成测试内容
        TextView tv = new TextView(mContext);
        if (i % 2 == 0) {
            tv.setBackgroundColor(Color.BLUE);
        } else {
            tv.setBackgroundColor(Color.GREEN);
        }
        tv.setTextColor(Color.WHITE);
        tv.setText("item:" + i);
        addView(tv);
        tv.layout(left, top, right, bottom);
        top += height;
        // 留20px的行间距
        top += MOCK_ITEM_COUNT;
    }
}
 
Example 5
Source Project: WidgetCase   File: CustomScrollViewTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int top = 0;
    for (int i = 0; i < MOCK_ITEM_COUNT; i++) {
        int width = mScreenW;
        int height = mScreenH / 2;
        int left = 0;
        int right = left + width;
        int bottom = top + height;

        // 计算控件实际宽高
        if (bottom > mHeight) {
            mHeight = bottom;
        }
        if (right > mWidth) {
            mWidth = right;
        }

        // 生成测试内容
        TextView tv = new TextView(mContext);
        if (i % 2 == 0) {
            tv.setBackgroundColor(Color.BLUE);
        } else {
            tv.setBackgroundColor(Color.GREEN);
        }
        tv.setTextColor(Color.WHITE);
        tv.setText("item:" + i);
        addView(tv);
        tv.layout(left, top, right, bottom);
        top += height;
        // 留20px的行间距
        top += MOCK_ITEM_COUNT;
    }
}
 
Example 6
Source Project: atlas   File: TextResize.java    License: Apache License 2.0 5 votes vote down vote up
private static void setTextViewData(TextView view, TextResizeData data, float fontSize) {
    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
    view.setPadding(data.paddingLeft, data.paddingTop, data.paddingRight, data.paddingBottom);
    view.setRight(view.getLeft() + data.width);
    view.setBottom(view.getTop() + data.height);
    view.setTextColor(data.textColor);
    int widthSpec = View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(view.getHeight(), View.MeasureSpec.EXACTLY);
    view.measure(widthSpec, heightSpec);
    view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
}
 
Example 7
Source Project: android-instant-apps   File: TextResize.java    License: Apache License 2.0 5 votes vote down vote up
private static void setTextViewData(TextView view, TextResizeData data, float fontSize) {
    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
    view.setPadding(data.paddingLeft, data.paddingTop, data.paddingRight, data.paddingBottom);
    view.setRight(view.getLeft() + data.width);
    view.setBottom(view.getTop() + data.height);
    view.setTextColor(data.textColor);
    int widthSpec = View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(view.getHeight(), View.MeasureSpec.EXACTLY);
    view.measure(widthSpec, heightSpec);
    view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
}
 
Example 8
Source Project: android-login   File: TextSizeTransition.java    License: MIT License 5 votes vote down vote up
private static void setTextViewData(TextView view, TextResizeData data, float fontSize) {
  view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
  view.setPadding(data.paddingLeft, data.paddingTop, data.paddingRight, data.paddingBottom);
  view.setRight(view.getLeft() + data.width);
  view.setBottom(view.getTop() + data.height);
  view.setTextColor(data.textColor);
  int widthSpec = View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY);
  int heightSpec = View.MeasureSpec.makeMeasureSpec(view.getHeight(), View.MeasureSpec.EXACTLY);
  view.measure(widthSpec, heightSpec);
  view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
}
 
Example 9
Source Project: glide-support   File: Generators.java    License: The Unlicense 5 votes vote down vote up
/** OP's original implementation fixed for real centering */
public static Bitmap imageWithText(Context context, Bitmap bitmap, GenerateParams params) {
	TextView view = new TextView(context);
	view.setText(params.text);
	view.setTextColor(params.color);
	view.setBackgroundColor(params.background);
	view.setTypeface(null, Typeface.BOLD);
	view.setGravity(Gravity.CENTER);
	view.setTextSize(20);
	Canvas canvas = new Canvas(bitmap);
	view.measure(makeMeasureSpec(canvas.getWidth(), EXACTLY), makeMeasureSpec(canvas.getHeight(), EXACTLY));
	view.layout(0, 0, canvas.getWidth(), canvas.getHeight());
	view.draw(canvas);
	return bitmap;
}
 
Example 10
protected void shareNoteImage() {
    final NoteHeadContentViewPair viewPair = getSnapShotViews();
    //contentTV.setText(Html.fromHtml(currentNoteInfo.content+"<br>分享来自NONo笔记", imageGetter, htmlTagHandler), TextView.BufferType.SPANNABLE);
    popupWindow = NotifyHelper.popUpWaitingAnimation(this,popupWindow);
    final TextView tv = new TextView(this);
    tv.setGravity(Gravity.CENTER);
    tv.setPadding(viewPair.contentView.getPaddingLeft(),0,0,0);
    tv.layout(0,0,findViewById(R.id.real_toolbar).getWidth(),findViewById(R.id.real_toolbar).getHeight()/2);
    tv.setBackgroundColor(getResources().getColor(android.R.color.white));
    tv.setTextColor(getResources().getColor(R.color.md_second_color));
    tv.setTextSize(getResources().getDimension(R.dimen.md_caption_text_size)/6);
    tv.setText("分享来自 NONo笔记 APP,via nonobiji.com");
    final Bitmap bitmap = ShareUtil.createViewBitmap(viewPair.headView,viewPair.contentView,tv);
    new Thread(new Runnable() {
        @Override
        public void run() {
            final String imagePath = ShareUtil.saveViewToPic(NoteDetailBaseActivity.this,bitmap);
            NoteDetailBaseActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(NoteDetailBaseActivity.this, "图片保存在" + imagePath, Toast.LENGTH_LONG).show();
                    NotifyHelper.popUpWaitingAnimationFinished(popupWindow);
                    ShareUtil.shareImage(NoteDetailBaseActivity.this,imagePath,"分享NONo笔记图片");
                }
            });

        }
    }).start();
}
 
Example 11
Source Project: AndroidDemo   File: ReflectionActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	final FrameLayout root = new FrameLayout(this);
	setContentView(root);

	final TextView textView = new TextView(this);
	textView.setText("test");
	textView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
	textView.setTextColor(Color.WHITE);
	textView.setTextSize(40);
	textView.setGravity(Gravity.CENTER_HORIZONTAL);
	textView.setBackgroundColor(Color.RED);
	textView.setPadding(100, 20, 100, 20);

	final int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
	textView.measure(measureSpec, measureSpec);
	textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
	final Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
	final Canvas c = new Canvas(b);
	textView.draw(c);

	final ImageView imageView = new ImageView(this);
	imageView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
	imageView.setImageBitmap(createReflection(b, 1, 10));
	root.addView(imageView);
}
 
Example 12
@Override
public Object instantiateItem(ViewGroup container, int position) {
    TextView headerTextView = new TextView(container.getContext());
    TextView messageTextView = new TextView(container.getContext());

    FrameLayout frameLayout = new FrameLayout(container.getContext()) {
        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            int oneFourth = (bottom - top) / 4;
            int y = (oneFourth * 3 - AndroidUtilities.dp(275)) / 2;
            y += AndroidUtilities.dp(166);
            int x = AndroidUtilities.dp(18);
            headerTextView.layout(x, y, x + headerTextView.getMeasuredWidth(), y + headerTextView.getMeasuredHeight());

            y += AndroidUtilities.dp(42);
            x = AndroidUtilities.dp(16);
            messageTextView.layout(x, y, x + messageTextView.getMeasuredWidth(), y + messageTextView.getMeasuredHeight());
        }
    };

    headerTextView.setTextColor(0xff212121);
    headerTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 26);
    headerTextView.setGravity(Gravity.CENTER);
    frameLayout.addView(headerTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 18, 244, 18, 0));

    messageTextView.setTextColor(0xff808080);
    messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    messageTextView.setGravity(Gravity.CENTER);
    frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 286, 16, 0));

    container.addView(frameLayout, 0);

    headerTextView.setText(titles[position]);
    messageTextView.setText(AndroidUtilities.replaceTags(messages[position]));

    return frameLayout;
}
 
Example 13
@Override
public Object instantiateItem(ViewGroup container, int position) {
    TextView headerTextView = new TextView(container.getContext());
    TextView messageTextView = new TextView(container.getContext());

    FrameLayout frameLayout = new FrameLayout(container.getContext()) {
        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            int oneFourth = (bottom - top) / 4;
            int y = (oneFourth * 3 - AndroidUtilities.dp(275)) / 2;
            y += AndroidUtilities.dp(166);
            int x = AndroidUtilities.dp(18);
            headerTextView.layout(x, y, x + headerTextView.getMeasuredWidth(), y + headerTextView.getMeasuredHeight());

            y += AndroidUtilities.dp(42);
            x = AndroidUtilities.dp(16);
            messageTextView.layout(x, y, x + messageTextView.getMeasuredWidth(), y + messageTextView.getMeasuredHeight());
        }
    };

    headerTextView.setTextColor(0xff212121);
    headerTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 26);
    headerTextView.setGravity(Gravity.CENTER);
    frameLayout.addView(headerTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 18, 244, 18, 0));

    messageTextView.setTextColor(0xff808080);
    messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    messageTextView.setGravity(Gravity.CENTER);
    frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 286, 16, 0));

    container.addView(frameLayout, 0);

    headerTextView.setText(titles[position]);
    messageTextView.setText(AndroidUtilities.replaceTags(messages[position]));

    return frameLayout;
}
 
Example 14
Source Project: MaterialWpp   File: FloatingActionMenu.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    System.out.println("onLayout:" + changed);
    if (changed) {
        int right = r - getPaddingRight();
        int bottom = b - getPaddingBottom();
        int top = bottom - mMenuButton.getMeasuredHeight();
        mMenuButton.layout(right - mMenuButton.getMeasuredWidth(), top, right, bottom);
        int dw = (mMenuButton.getMeasuredWidth() - mIcon.getMeasuredWidth()) / 2;
        int dh = (mMenuButton.getMeasuredHeight() - mIcon.getMeasuredHeight()) / 2;
        mIcon.layout(right - mIcon.getMeasuredWidth() - dw,
                bottom - mIcon.getMeasuredHeight() - dh, right - dw, bottom - dh);

        if (isCircle) {
            if (mMenuItems.size() < 2) {
                Log.e("onLayout", "Floating Action Buttons must more then one!");
                return;
            }
            double angle = Math.PI/2d/(mMenuItems.size() - 1);
            for (int i = 0; i < mMenuItems.size(); i++) {
                FloatingActionButton itemFB = mMenuItems.get(i);
                int fbWidth = itemFB.getMeasuredWidth();
                int fbHeight = itemFB.getMeasuredHeight();
                if (0 != multipleOfFB) {
                    mRadius = (int) (fbWidth * multipleOfFB);
                }
                int itemDw = (mMenuButton.getMeasuredWidth() - fbWidth) / 2;
                int itemDh = (mMenuButton.getMeasuredHeight() - fbHeight) / 2;
                int itemX = (int) (mRadius*Math.cos(i*angle));
                int itemY = (int) (mRadius*Math.sin(i*angle));
                itemFB.layout(right - itemX - fbWidth - itemDw, bottom - itemY - fbHeight - itemDh,
                        right - itemX - itemDw, bottom - itemY - itemDh);

                if (!animating) {
                    if (!mOpen) {
                        itemFB.setTranslationY(mMenuButton.getTop() - itemFB.getTop());
                        itemFB.setTranslationX(mMenuButton.getLeft() - itemFB.getLeft());
                        itemFB.setVisibility(GONE);
                    } else {
                        itemFB.setTranslationY(0);
                        itemFB.setTranslationX(0);
                        itemFB.setVisibility(VISIBLE);
                    }
                }
            }
        } else {
            for (int i = 0; i < mMenuItems.size(); i++) {
                FloatingActionButton item = mMenuItems.get(i);
                TextView label = mMenuItemLabels.get(i);

                label.setBackgroundResource(R.drawable.rounded_corners);
                bottom = top -= mItemGap;

                top -= item.getMeasuredHeight();
                int width = item.getMeasuredWidth();
                int d = (mMenuButton.getMeasuredWidth() - width) / 2;
                item.layout(right - width - d, top, right - d, bottom);
                d = (item.getMeasuredHeight() - label.getMeasuredHeight()) / 2;

                label.layout(item.getLeft() - label.getMeasuredWidth() - 50,
                        item.getTop() + d, item.getLeft(),
                        item.getTop() + d + label.getMeasuredHeight());
                if (!animating) {
                    if (!mOpen) {
                        item.setTranslationY(mMenuButton.getTop() - item.getTop());
                        item.setVisibility(GONE);
                        label.setVisibility(GONE);
                    } else {
                        item.setTranslationY(0);
                        item.setVisibility(VISIBLE);
                        label.setVisibility(VISIBLE);
                    }
                }
            }
        }
        if (!animating && getBackground() != null) {
            if (!mOpen) {
                getBackground().setAlpha(0);
            } else {
                getBackground().setAlpha(0xff);
            }
        }
    }
}
 
Example 15
/**
 * Sets the layout of the ViewGroup dependent on the number of menu items as well as menu direction.
 */
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    System.out.println("onLayout:" + changed);
    if (changed) {
        int right = r - getPaddingRight();
        int bottom = b - getPaddingBottom();
        int top = bottom - mMenuButton.getMeasuredHeight();
        mMenuButton.layout(right - mMenuButton.getMeasuredWidth(), top, right, bottom);
        int dw = (mMenuButton.getMeasuredWidth() - mIcon.getMeasuredWidth()) / 2;
        int dh = (mMenuButton.getMeasuredHeight() - mIcon.getMeasuredHeight()) / 2;
        mIcon.layout(right - mIcon.getMeasuredWidth() - dw,
                bottom - mIcon.getMeasuredHeight() - dh, right - dw, bottom - dh);

        if (isCircle) {
            if (mMenuItems.size() < 2) {
                Log.e("onLayout", "Floating Action Buttons must more then one!");
                return;
            }
            double angle = Math.PI/2d/(mMenuItems.size() - 1);
            for (int i = 0; i < mMenuItems.size(); i++) {
                FloatingActionButton itemFB = mMenuItems.get(i);
                int fbWidth = itemFB.getMeasuredWidth();
                int fbHeight = itemFB.getMeasuredHeight();
                if (0 != multipleOfFB) {
                    mRadius = (int) (fbWidth * multipleOfFB);
                }
                int itemDw = (mMenuButton.getMeasuredWidth() - fbWidth) / 2;
                int itemDh = (mMenuButton.getMeasuredHeight() - fbHeight) / 2;
                int itemX = (int) (mRadius*Math.cos(i*angle));
                int itemY = (int) (mRadius*Math.sin(i*angle));
                itemFB.layout(right - itemX - fbWidth - itemDw, bottom - itemY - fbHeight - itemDh,
                        right - itemX - itemDw, bottom - itemY - itemDh);

                if (!animating) {
                    if (!mOpen) {
                        itemFB.setTranslationY(mMenuButton.getTop() - itemFB.getTop());
                        itemFB.setTranslationX(mMenuButton.getLeft() - itemFB.getLeft());
                        itemFB.setVisibility(GONE);
                    } else {
                        itemFB.setTranslationY(0);
                        itemFB.setTranslationX(0);
                        itemFB.setVisibility(VISIBLE);
                    }
                }
            }
        } else {
            for (int i = 0; i < mMenuItems.size(); i++) {
                FloatingActionButton item = mMenuItems.get(i);
                TextView label = mMenuItemLabels.get(i);

                label.setBackgroundResource(R.drawable.rounded_corners);
                bottom = top -= mItemGap;

                top -= item.getMeasuredHeight();
                int width = item.getMeasuredWidth();
                int d = (mMenuButton.getMeasuredWidth() - width) / 2;
                item.layout(right - width - d, top, right - d, bottom);
                d = (item.getMeasuredHeight() - label.getMeasuredHeight()) / 2;

                label.layout(item.getLeft() - label.getMeasuredWidth() - 50,
                        item.getTop() + d, item.getLeft(),
                        item.getTop() + d + label.getMeasuredHeight());
                if (!animating) {
                    if (!mOpen) {
                        item.setTranslationY(mMenuButton.getTop() - item.getTop());
                        item.setVisibility(GONE);
                        label.setVisibility(GONE);
                    } else {
                        item.setTranslationY(0);
                        item.setVisibility(VISIBLE);
                        label.setVisibility(VISIBLE);
                    }
                }
            }
        }
        if (!animating && getBackground() != null) {
            if (!mOpen) {
                getBackground().setAlpha(0);
            } else {
                getBackground().setAlpha(0xff);
            }
        }
    }
}
 
Example 16
Source Project: settlers-remake   File: AndroidTextDrawer.java    License: MIT License 4 votes vote down vote up
private int findLineFor(String string) {
	int line = findExistingString(string);
	if (line >= 0) {
		return line;
	}

	int width = (int) Math.ceil(computeWidth(string) + 25);
	renderer = new TextView(context.getAndroidContext());
	renderer.setTextColor(Color.WHITE);
	renderer.setSingleLine(true);
	renderer.setTextSize(TypedValue.COMPLEX_UNIT_PX, getScaledSize());
	renderer.setText(string);

	int firstLine = findLineToUse();
	// System.out.println("string cache miss for " + string +
	// ", allocating new line: " + firstLine);
	int lastLine = firstLine;

	for (int x = 0; x < width; x += TEXTURE_WIDTH) {
		if (x == 0) {
			line = firstLine;
		} else {
			line = findLineToUse();
			nextTile[lastLine] = line;
			linestrings[line] = null;
			linewidths[line] = -1;
		}
		// important to not allow cycles.
		lastused[line] = Integer.MAX_VALUE;
		// just to be sure.
		nextTile[line] = -1;

		// render the new text to that line.
		Bitmap bitmap = Bitmap.createBitmap(TEXTURE_WIDTH, lineheight, Bitmap.Config.ALPHA_8);
		Canvas canvas = new Canvas(bitmap);
		renderer.layout(0, 0, width, lineheight);
		canvas.translate(-x, 0);
		renderer.draw(canvas);
		// canvas.translate(50, .8f * lineheight);
		int points = lineheight * TEXTURE_WIDTH;
		ByteBuffer alpha8 = ByteBuffer.allocateDirect(points);
		bitmap.copyPixelsToBuffer(alpha8);
		ByteBuffer updateBuffer;
		if(context instanceof GLES20DrawContext) {
			updateBuffer = ByteBuffer.allocateDirect(points*4);
			for(int i = 0;i != points;i++) {
				updateBuffer.putInt(0xFFFFFF00|alpha8.get(i));
			}
		} else {
			updateBuffer = alpha8;
		}
		updateBuffer.rewind();
		context.updateFontTexture(texture, 0, line*lineheight, TEXTURE_WIDTH, lineheight, updateBuffer);
		lastLine = line;
	}
	lastused[firstLine] = lastUsedCount++;
	linestrings[firstLine] = string;
	linewidths[firstLine] = width;

	checkInvariants();
	return firstLine;
}