本文整理匯總了Java中android.widget.TextView.layout方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.layout方法的具體用法?Java TextView.layout怎麽用?Java TextView.layout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TextView
的用法示例。
在下文中一共展示了TextView.layout方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDraw
import android.widget.TextView; //導入方法依賴的package包/類
@[email protected]("DrawAllocation")
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode()) {//這段代碼在運行時不會執行,隻會在Studio編輯預覽時運行,不用在意性能問題
int d = DensityUtil.dp2px(5);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(0x44ffffff);
paint.setStrokeWidth(DensityUtil.dp2px(1));
paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
canvas.drawRect(d, d, getWidth() - d, getBottom() - d, paint);
TextView textView = new TextView(getContext());
textView.setText(getClass().getSimpleName()+" 虛假區域\n運行時代表下拉Header的高度【" + DensityUtil.px2dp(getHeight()) + "dp】\n而不會顯示任何東西");
textView.setTextColor(0x44ffffff);
textView.setGravity(Gravity.CENTER);
textView.measure(makeMeasureSpec(getWidth(), EXACTLY), makeMeasureSpec(getHeight(), EXACTLY));
textView.layout(0, 0, getWidth(), getHeight());
textView.draw(canvas);
}
}
示例2: onDraw
import android.widget.TextView; //導入方法依賴的package包/類
@[email protected]("DrawAllocation")
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode()) {//這段代碼在運行時不會執行,隻會在Studio編輯預覽時運行,不用在意性能問題
int d = DensityUtil.dp2px(5);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(0x44ffffff);
paint.setStrokeWidth(DensityUtil.dp2px(1));
paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
canvas.drawRect(d, d, getWidth() - d, getBottom() - d, paint);
TextView textView = new TextView(getContext());
textView.setText(getClass().getSimpleName()+" 虛假區域\n運行時代表上拉Footer的高度【" + DensityUtil.px2dp(getHeight()) + "dp】\n而不會顯示任何東西");
textView.setTextColor(0x44ffffff);
textView.setGravity(Gravity.CENTER);
textView.measure(makeMeasureSpec(getWidth(), EXACTLY), makeMeasureSpec(getHeight(), EXACTLY));
textView.layout(0, 0, getWidth(), getHeight());
textView.draw(canvas);
}
}
示例3: onDraw
import android.widget.TextView; //導入方法依賴的package包/類
@Override
@SuppressLint("DrawAllocation")
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode()) {//這段代碼在運行時不會執行,隻會在Studio編輯預覽時運行,不用在意性能問題
int d = DensityUtil.dp2px(5);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(0x44ffffff);
paint.setStrokeWidth(DensityUtil.dp2px(1));
paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
canvas.drawRect(d, d, getWidth() - d, getBottom() - d, paint);
TextView textView = new TextView(getContext());
textView.setText(getClass().getSimpleName()+" 虛假區域\n運行時代表下拉Header的高度【" + DensityUtil.px2dp(getHeight()) + "dp】\n而不會顯示任何東西");
textView.setTextColor(0x44ffffff);
textView.setGravity(Gravity.CENTER);
textView.measure(makeMeasureSpec(getWidth(), EXACTLY), makeMeasureSpec(getHeight(), EXACTLY));
textView.layout(0, 0, getWidth(), getHeight());
textView.draw(canvas);
}
}
示例4: onDraw
import android.widget.TextView; //導入方法依賴的package包/類
@Override
@SuppressLint("DrawAllocation")
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode()) {//這段代碼在運行時不會執行,隻會在Studio編輯預覽時運行,不用在意性能問題
int d = DensityUtil.dp2px(5);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(0x44ffffff);
paint.setStrokeWidth(DensityUtil.dp2px(1));
paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
canvas.drawRect(d, d, getWidth() - d, getBottom() - d, paint);
TextView textView = new TextView(getContext());
textView.setText(getClass().getSimpleName()+" 虛假區域\n運行時代表上拉Footer的高度【" + DensityUtil.px2dp(getHeight()) + "dp】\n而不會顯示任何東西");
textView.setTextColor(0x44ffffff);
textView.setGravity(Gravity.CENTER);
textView.measure(makeMeasureSpec(getWidth(), EXACTLY), makeMeasureSpec(getHeight(), EXACTLY));
textView.layout(0, 0, getWidth(), getHeight());
textView.draw(canvas);
}
}
示例5: onDraw
import android.widget.TextView; //導入方法依賴的package包/類
@[email protected]("DrawAllocation")
protected final void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode()) {//這段代碼在運行時不會執行,隻會在Studio編輯預覽時運行,不用在意性能問題
int d = DensityUtil.dp2px(5);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(0x44ffffff);
paint.setStrokeWidth(DensityUtil.dp2px(1));
paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
canvas.drawRect(d, d, getWidth() - d, getBottom() - d, paint);
TextView textView = new TextView(getContext());
textView.setText(getClass().getSimpleName()+" 虛假區域\n運行時代表下拉Header的高度【" + DensityUtil.px2dp(getHeight()) + "dp】\n而不會顯示任何東西");
textView.setTextColor(0x44ffffff);
textView.setGravity(Gravity.CENTER);
textView.measure(makeMeasureSpec(getWidth(), EXACTLY), makeMeasureSpec(getHeight(), EXACTLY));
textView.layout(0, 0, getWidth(), getHeight());
textView.draw(canvas);
}
}
示例6: onDraw
import android.widget.TextView; //導入方法依賴的package包/類
@Override
@SuppressLint({"DrawAllocation", "SetTextI18n"})
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode()) {//這段代碼在運行時不會執行,隻會在Studio編輯預覽時運行,不用在意性能問題
int d = DensityUtil.dp2px(5);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(0x44ffffff);
paint.setStrokeWidth(DensityUtil.dp2px(1));
paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
canvas.drawRect(d, d, getWidth() - d, getBottom() - d, paint);
TextView textView = new TextView(getContext());
textView.setText(getClass().getSimpleName()+" 虛假區域\n運行時代表下拉Header的高度【" + DensityUtil.px2dp(getHeight()) + "dp】\n而不會顯示任何東西");
textView.setTextColor(0x44ffffff);
textView.setGravity(Gravity.CENTER);
textView.measure(makeMeasureSpec(getWidth(), EXACTLY), makeMeasureSpec(getHeight(), EXACTLY));
textView.layout(0, 0, getWidth(), getHeight());
textView.draw(canvas);
}
}
示例7: onDraw
import android.widget.TextView; //導入方法依賴的package包/類
@Override
@SuppressLint({"DrawAllocation", "SetTextI18n"})
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode()) {//這段代碼在運行時不會執行,隻會在Studio編輯預覽時運行,不用在意性能問題
int d = DensityUtil.dp2px(5);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(0x44ffffff);
paint.setStrokeWidth(DensityUtil.dp2px(1));
paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
canvas.drawRect(d, d, getWidth() - d, getBottom() - d, paint);
TextView textView = new TextView(getContext());
textView.setText(getClass().getSimpleName()+" 虛假區域\n運行時代表上拉Footer的高度【" + DensityUtil.px2dp(getHeight()) + "dp】\n而不會顯示任何東西");
textView.setTextColor(0x44ffffff);
textView.setGravity(Gravity.CENTER);
textView.measure(makeMeasureSpec(getWidth(), EXACTLY), makeMeasureSpec(getHeight(), EXACTLY));
textView.layout(0, 0, getWidth(), getHeight());
textView.draw(canvas);
}
}
示例8: createClusterIcon
import android.widget.TextView; //導入方法依賴的package包/類
@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);
}
示例9: createLabelBitmap
import android.widget.TextView; //導入方法依賴的package包/類
public Bitmap createLabelBitmap(String label) {
if (DBG) Log.d(TAG, "createLabelBitmap : label="+ label);
mLabelView = (TextView)mLayoutInflater.inflate(R.layout.cover_roll_label, null);
mLabelView.setText(label);
mLabelView.setLayoutParams( new FrameLayout.LayoutParams(NO_SIZE_LIMIT,NO_SIZE_LIMIT) );
mLabelView.measure(NO_SIZE_LIMIT, NO_SIZE_LIMIT);
final int width = mLabelView.getMeasuredWidth();
final int height = mLabelView.getMeasuredHeight();
if(DBG) Log.d(TAG, "createLabelBitmap: mLabelView size = "+width+"x"+height);
mLabelView.layout(0, 0, width, height);
StaticLayout textLayout = null;
if (isRtlLabel()) {
// Archos hack : when a right-to-left language is selected calling TextView.draw()
// draws the background but not the text, so also call TextLayout.draw() which works
textLayout = createTextLayout(label, Color.LTGRAY, mContentLabelFontsize, width);
}
return createViewBitmap(mLabelView, textLayout, width, height, ALIGN_BOTTOM);
}
示例10: setTextViewData
import android.widget.TextView; //導入方法依賴的package包/類
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());
}
示例11: snapShotLabelView
import android.widget.TextView; //導入方法依賴的package包/類
private void snapShotLabelView(String title) {
LayoutInflater inflater = LayoutInflater.from(context);
TextView labelView = (TextView) inflater.inflate(R.layout.view_label, null, false);
labelView.setText(title);
int width = (int) context.getResources().getDimension(R.dimen.label_width);
int height = (int) context.getResources().getDimension(R.dimen.label_height);
labelRatio = width / height ;
imageTitle = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(imageTitle);
labelView.layout(0, 0, width, height);
labelView.draw(canvas);
}
示例12: drawInflat
import android.widget.TextView; //導入方法依賴的package包/類
private void drawInflat(Canvas c, RecyclerView parent, String tag) {
TextView toDrawView = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.title_item, parent, false);
toDrawView.setText(tag);
int toDrawWidthSpec;//用於測量的widthMeasureSpec
int toDrawHeightSpec;//用於測量的heightMeasureSpec
//拿到複雜布局的LayoutParams,如果為空,就new一個。
// 後麵需要根據這個lp 構建toDrawWidthSpec,toDrawHeightSpec
ViewGroup.LayoutParams lp = toDrawView.getLayoutParams();
if (lp == null) {
lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);//這裏是根據複雜布局layout的width height,new一個Lp
toDrawView.setLayoutParams(lp);
}
if (lp.width == ViewGroup.LayoutParams.MATCH_PARENT) {
//如果是MATCH_PARENT,則用父控件能分配的最大寬度和EXACTLY構建MeasureSpec。
toDrawWidthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight(), View.MeasureSpec.EXACTLY);
} else if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) {
//如果是WRAP_CONTENT,則用父控件能分配的最大寬度和AT_MOST構建MeasureSpec。
toDrawWidthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight(), View.MeasureSpec.AT_MOST);
} else {
//否則則是具體的寬度數值,則用這個寬度和EXACTLY構建MeasureSpec。
toDrawWidthSpec = View.MeasureSpec.makeMeasureSpec(lp.width, View.MeasureSpec.EXACTLY);
}
//高度同理
if (lp.height == ViewGroup.LayoutParams.MATCH_PARENT) {
toDrawHeightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight() - parent.getPaddingTop() - parent.getPaddingBottom(), View.MeasureSpec.EXACTLY);
} else if (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
toDrawHeightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight() - parent.getPaddingTop() - parent.getPaddingBottom(), View.MeasureSpec.AT_MOST);
} else {
toDrawHeightSpec = View.MeasureSpec.makeMeasureSpec(lp.width, View.MeasureSpec.EXACTLY);
}
//依次調用 measure,layout,draw方法,將複雜頭部顯示在屏幕上。
toDrawView.measure(toDrawWidthSpec, toDrawHeightSpec);
toDrawView.layout(parent.getPaddingLeft(), parent.getPaddingTop(),
parent.getPaddingLeft() + toDrawView.getMeasuredWidth(), parent.getPaddingTop() + toDrawView.getMeasuredHeight());
toDrawView.draw(c);
}