本文整理了Java中android.widget.TextView.layout()
方法的一些代码示例,展示了TextView.layout()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.layout()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:layout
暂无
代码示例来源:origin: seven332/EhViewer
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int width = r - l;
int height = b - t;
switch (mStep) {
case 0:
mLeftText.layout(0, 0, width / 3, height);
mRightText.layout(width * 2 / 3, 0, width, height);
mMenuText.layout(width / 3, 0, width * 2 / 3, height / 2);
mProgressText.layout(width / 3, height / 2, width * 2 / 3, height);
break;
default:
case 1:
mLongClickText.layout(0, 0, width, height);
break;
}
}
代码示例来源:origin: stackoverflow.com
view.layout(0, 0, rect.width(), rect.height());
代码示例来源:origin: rey5137/material
if(mAddressView.getVisibility() == View.VISIBLE){
childTop = (childBottom - mNameView.getMeasuredHeight() - mAddressView.getMeasuredHeight()) / 2;
mNameView.layout(childLeft, childTop, childRight - mSpacing, childTop + mNameView.getMeasuredHeight());
childTop += mNameView.getMeasuredHeight();
mAddressView.layout(childLeft, childTop, childRight - mSpacing, childTop + mAddressView.getMeasuredHeight());
mNameView.layout(childLeft, childTop, childRight - mSpacing, childTop + mNameView.getMeasuredHeight());
mAddressView.layout(childLeft, childTop, childRight - mSpacing, childTop + mAddressView.getMeasuredHeight());
代码示例来源:origin: qiujuer/Genius-Android
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int left = getPaddingLeft();
int top = getPaddingTop();
int right = getWidth() - getPaddingRight();
int bottom = getHeight() - getPaddingBottom();
//the TetView is always layout at the top
mNumber.layout(left, top, left + mWidth, top + mWidth);
//the MarkerDrawable uses the whole view, it will adapt itself...
// or it seems so...
mBalloonMarkerDrawable.setBounds(left, top, right, bottom);
}
代码示例来源:origin: willowtreeapps/Hyperion-Android
/**
* Lays out textview to (text dimensions + padding) * system font scale
* Padding based on screen density
*
* @param tv The TextView to layout
*/
private void layoutTextView(TextView tv) {
final float fontScale = getResources().getConfiguration().fontScale;
/*
* Multiplier for padding based on phone density
* Density of 2 does not need padding
*/
final float densityMultiplier = getContext().getResources().getDisplayMetrics().density - 2;
Rect bounds = new Rect();
paintText.getTextBounds(tv.getText().toString().toCharArray(), 0, tv.getText().length(), bounds);
tv.layout(0, 0, (int) ((bounds.width() + (33 * densityMultiplier)) * fontScale),
(int) ((bounds.height() + (22 * densityMultiplier)) * fontScale));
}
}
代码示例来源:origin: stackoverflow.com
TextView myTextView = new TextView(mContext);
myTextView.setBackgroundColor(0xFFFF9900);
myTextView.layout(left, top, right, bottom);
ViewGroup.LayoutParams textViewParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
myTextView.setLayoutParams(textViewParams);
myTextView.setGravity(Gravity.CENTER); // with this, the text is centered horizontally but is still on top. There is plenty of space below
this.addView(myTextView);
代码示例来源:origin: lguipeng/BubbleView
@Override
public void layout(int l, int t, int r, int b) {
super.layout(l, t, r, b);
setUp();
}
代码示例来源:origin: dongorigin/AndroidDemo
@Override
public void layout(int l, int t, int r, int b) {
super.layout(l, t, r, b);
L.d(TAG, "left %d top %d right %d bottom %d", l, t, r, b);
}
代码示例来源:origin: stackoverflow.com
TextView textView = new TextView(getContext());
int width = (int) (rect.right - rect.left);
int height = (int) (rect.bottom - rect.top);
textView.layout(0, 0, width, height);
textView.setText(e.getSummary());
Bitmap bitmapText = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvasText = new Canvas(bitmapText);
textView.draw(canvasText);
canvas.drawBitmap(bitmapText, rect.left, rect.top, null);
代码示例来源:origin: stackoverflow.com
TextView usertext = new TextView(this);
usertext.setText("Hi Hello");
usertext.setTextSize(22);
usertext.setBackgroundColor(Color.TRANSPARENT);
Bitmap testB;
testB = Bitmap.createBitmap(TextLayout.getWidth(), TextLayout.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(testB);
usertext.layout(0, 0, 80, 100);
usertext.draw(c);
// create imageview in layout file and declare here
Imageview iv = (Imageview) findviewByid(your imageview id)
iv.setImageBitmap(testB);
iv.setOnTouchListener(this);
代码示例来源:origin: stackoverflow.com
// ...
PdfDocument.Page page = document.startPage(pageInfo);
TextView textView = new TextView(ctx);
textView.setText("1,2,3");
// here the solution
int left = 0;
int top = 0;
int width = 200;
int height = 200;
textView.layout(0,0,width,height);
canvas.save()
canvas.translate(left,top);
textView.draw(page.getCanvas());
canvas.restore()
代码示例来源:origin: stackoverflow.com
TextView textView = new TextView(getContext());
textView.setText(DetailsActivity.temp_desc);
textView.setMinLines(1);
canvas.translate(0,bitmap.getHeight());
textView.layout(0, 0, 500, 150);
textView.draw(canvas);
代码示例来源:origin: stackoverflow.com
private Bitmap loadBitmap(int width, int height, int index) {
Bitmap txtBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
String text1 = yourPagesStringArray[index];
Canvas c = new Canvas(txtBitmap);
TextView tv = new TextView(getApplicationContext());
tv.setText(text1);
tv.setTextColor(0xa00050ff);
tv.setTextSize(15);
tv.setLinksClickable(true);
tv.setLineSpacing(2, 2);
tv.layout(0, 0, getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels);
tv.draw(c);
c.drawBitmap(txtBitmap, 0, 0, null);
return txtBitmap;
}
代码示例来源:origin: rockon999/LeanbackLauncher
protected void layoutChild(TextView view, int start, int top, int parentWidth, boolean isLayoutRtl) {
if (isLayoutRtl) {
view.layout((parentWidth - start) - view.getMeasuredWidth(), top, parentWidth - start, view.getMeasuredHeight() + top);
} else {
view.layout(start, top, view.getMeasuredWidth() + start, view.getMeasuredHeight() + top);
}
}
代码示例来源:origin: stackoverflow.com
public Drawable createFromView(int positionNumber)
{
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.drawable.pin_icon, null, false);
TextView tv = (TextView) view.findViewById(R.id.pin_background);
tv.setText(" "+ (positionNumber+1) ); // +1 since position is starting from 0
tv.setDrawingCacheEnabled(true);
tv.layout(0, 0, 50, 50);
tv.buildDrawingCache();
Bitmap b = Bitmap.createBitmap(tv.getDrawingCache());
tv.setDrawingCacheEnabled(false);
Drawable d = new BitmapDrawable(b);
return d;
}
代码示例来源:origin: stackoverflow.com
TextView textV = new TextView(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(128, 128);
textV.setLayoutParams(layoutParams);
textV.setTextColor(Color.WHITE);
textV.setBackgroundColor(Color.TRANSPARENT);
textV.setGravity(Gravity.CENTER);
textV.setText(text);
textV.setDrawingCacheEnabled(true);
Bitmap b = Bitmap.createBitmap( textV.getLayoutParams().width, textV.getLayoutParams().height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
textV.layout(0, 0, textV.getLayoutParams().width, textV.getLayoutParams().height);
textV.draw(c);
textV.setDrawingCacheEnabled(false);
代码示例来源:origin: stackoverflow.com
TextView upTextView = (TextView) getLayoutInflater().inflate(
R.layout.up_text, null);
upTextView.setText("CITIES");
upTextView.measure(0, 0);
upTextView.layout(0, 0, upTextView.getMeasuredWidth(),
upTextView.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(upTextView.getMeasuredWidth(),
upTextView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
upTextView.draw(canvas);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
代码示例来源:origin: DroidsOnRoids/Workcation
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());
}
代码示例来源:origin: googlesamples/android-unsplash
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());
}
代码示例来源:origin: bacy/titlebar
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
mLeftText.layout(0, mStatusBarHeight, mLeftText.getMeasuredWidth(), mLeftText.getMeasuredHeight() + mStatusBarHeight);
mRightLayout.layout(mScreenWidth - mRightLayout.getMeasuredWidth(), mStatusBarHeight,
mScreenWidth, mRightLayout.getMeasuredHeight() + mStatusBarHeight);
if (mLeftText.getMeasuredWidth() > mRightLayout.getMeasuredWidth()) {
mCenterLayout.layout(mLeftText.getMeasuredWidth(), mStatusBarHeight,
mScreenWidth - mLeftText.getMeasuredWidth(), getMeasuredHeight());
} else {
mCenterLayout.layout(mRightLayout.getMeasuredWidth(), mStatusBarHeight,
mScreenWidth - mRightLayout.getMeasuredWidth(), getMeasuredHeight());
}
mDividerView.layout(0, getMeasuredHeight() - mDividerView.getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight());
}
内容来源于网络,如有侵权,请联系作者删除!