当前位置: 首页>>代码示例>>Java>>正文


Java TextView.measure方法代码示例

本文整理汇总了Java中android.widget.TextView.measure方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.measure方法的具体用法?Java TextView.measure怎么用?Java TextView.measure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.TextView的用法示例。


在下文中一共展示了TextView.measure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:FalsifyHeader.java

示例2: 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);
    }
}
 
开发者ID:penghuanliang,项目名称:Rxjava2.0Demo,代码行数:24,代码来源:FalsifyHeader.java

示例3: 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);
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:21,代码来源:ArtworkFactory.java

示例4: 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);
    }
}
 
开发者ID:Brave-wan,项目名称:SmartRefresh,代码行数:23,代码来源:FalsifyHeader.java

示例5: 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);
    }
}
 
开发者ID:scwang90,项目名称:SmartRefreshLayout,代码行数:24,代码来源:FalsifyHeader.java

示例6: 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());
}
 
开发者ID:googlesamples,项目名称:android-instant-apps,代码行数:12,代码来源:TextResize.java

示例7: getHeight

import android.widget.TextView; //导入方法依赖的package包/类
/**
 * 在绘制之前,测量 TextView 的高度
 * @param context  上下文
 * @param text 内容
 * @param textSize sp
 * @param deviceWidth TextView 所在容器的宽度[重要]
 * @param typeface 加粗等等样式
 * @param padding 内间距
 * @return TextView 的高度
 */
public int getHeight(Context context, CharSequence text, int textSize, int deviceWidth, Typeface typeface, int padding) {
    TextView textView = new TextView(context);
    textView.setPadding(padding,padding,padding,padding);
    textView.setTypeface(typeface);
    textView.setText(text, TextView.BufferType.SPANNABLE);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(deviceWidth, View.MeasureSpec.AT_MOST);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(widthMeasureSpec, heightMeasureSpec);
    return textView.getMeasuredHeight();
}
 
开发者ID:didikee,项目名称:cnBetaGeek,代码行数:22,代码来源:CommentsView.java

示例8: initView

import android.widget.TextView; //导入方法依赖的package包/类
private void initView() {
    RelativeLayout layout = new RelativeLayout(mContext);
    RelativeLayout.LayoutParams params =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    mGood = new TextView(mContext);
    mGood.setIncludeFontPadding(false);
    mGood.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mTextSize);
    mGood.setTextColor(ContextCompat.getColor(mContext, mTextColor));
    mGood.setText(mText);
    mGood.setLayoutParams(params);
    layout.addView(mGood);
    setContentView(layout);

    int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    mGood.measure(w, h);
    setWidth(mGood.getMeasuredWidth());
    setHeight(mDistance + mGood.getMeasuredHeight());
    setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    setFocusable(false);
    setTouchable(false);
    setOutsideTouchable(false);

    mAnimationSet = createAnimation();
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:30,代码来源:GoodView.java

示例9: initView

import android.widget.TextView; //导入方法依赖的package包/类
private void initView() {
    RelativeLayout layout = new RelativeLayout(mContext);
    RelativeLayout.LayoutParams params =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    mGood = new TextView(mContext);
    mGood.setIncludeFontPadding(false);
    mGood.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mTextSize);
    mGood.setTextColor(mTextColor);
    mGood.setText(mText);
    mGood.setLayoutParams(params);
    layout.addView(mGood);
    setContentView(layout);

    int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    mGood.measure(w, h);
    setWidth(mGood.getMeasuredWidth());
    setHeight(mDistance + mGood.getMeasuredHeight());
    setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    setFocusable(false);
    setTouchable(false);
    setOutsideTouchable(false);

    mAnimationSet = createAnimation();
}
 
开发者ID:ruiqiao2017,项目名称:Renrentou,代码行数:30,代码来源:GoodView.java

示例10: getMeasuredWidth

import android.widget.TextView; //导入方法依赖的package包/类
private int getMeasuredWidth(@NonNull Context context) {
    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int maxWidth = context.getResources().getDimensionPixelSize(R.dimen.popup_max_width);
    int minWidth = context.getResources().getDimensionPixelSize(R.dimen.popup_min_width);
    String longestText = "";
    for (PopupItem item : mAdapter.getItems()) {
        if (item.getTitle().length() > longestText.length())
            longestText = item.getTitle();
    }

    int padding = context.getResources().getDimensionPixelSize(R.dimen.content_margin);
    int iconSize = context.getResources().getDimensionPixelSize(R.dimen.icon_size_small);
    TextView textView = new TextView(context);
    textView.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setTypeface(TypefaceHelper.getRegular(context));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources()
            .getDimension(R.dimen.text_content_subtitle));
    textView.setPadding(padding + iconSize + padding, 0, padding, 0);
    textView.setText(longestText);

    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(metrics.widthPixels, View.MeasureSpec.AT_MOST);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(widthMeasureSpec, heightMeasureSpec);

    int measuredWidth = textView.getMeasuredWidth() + padding;
    if (measuredWidth <= minWidth) {
        return minWidth;
    }

    if (measuredWidth >= minWidth && measuredWidth <= maxWidth) {
        return measuredWidth;
    }
    return maxWidth;
}
 
开发者ID:danimahardhika,项目名称:wallpaperboard,代码行数:38,代码来源:Popup.java

示例11: getShortHeight

import android.widget.TextView; //导入方法依赖的package包/类
/**
 * 要伸缩文本的高度 宽度固定的MeasureSpec.EXACTLY 高度MeasureSpec.AT_MOST
 *
 * @return
 */
public int getShortHeight() {
    int measuredWidth = contentTextView.getMeasuredWidth();
    TextView copyTextView = new TextView(getContext());
    copyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 8);
    int widthMeasureSpec = MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY);
    copyTextView.setMaxLines(3);//设置默认不展开的情况下显示3行
    copyTextView.setLines(3);//文本设置3行 不够3行显示3行的高度
    int heightMeasureSpec = MeasureSpec.makeMeasureSpec(2000, MeasureSpec.AT_MOST);
    copyTextView.measure(widthMeasureSpec, heightMeasureSpec);
    return copyTextView.getMeasuredHeight();
}
 
开发者ID:guzhigang001,项目名称:Bailan,代码行数:17,代码来源:FoldingTextView.java

示例12: getTileHeight

import android.widget.TextView; //导入方法依赖的package包/类
/**
 * Title的高度(更新 应用介绍 权限 这几个字) 宽度是固定的MeasureSpec.EXACTLY
 *
 * @return
 */
public int getTileHeight() {
    int measuredWidth = titleTextView.getMeasuredWidth();
    TextView copyTextView = new TextView(getContext());
    copyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    int widthMeasureSpec = MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY);
    copyTextView.setMaxLines(1);
    copyTextView.setLines(1);
    int heightMeasureSpec = MeasureSpec.makeMeasureSpec(2000, MeasureSpec.AT_MOST);//MeasureSpec.AT_MOST情况下前一个参数设置多少无所谓
    copyTextView.measure(widthMeasureSpec, heightMeasureSpec);
    return copyTextView.getMeasuredHeight();
}
 
开发者ID:guzhigang001,项目名称:Bailan,代码行数:17,代码来源:FoldingTextView.java

示例13: getHeight

import android.widget.TextView; //导入方法依赖的package包/类
/**
 * 获取TextView的高度
 * @param context
 * @param text
 * @param textSize
 * @param deviceWidth
 * @param typeface
 * @param padding
 * @return
 */
public static int getHeight(Context context, CharSequence text, int textSize, int deviceWidth, Typeface typeface, int padding) {
    TextView textView = new TextView(context);
    textView.setPadding(padding,0,padding,padding);
    textView.setTypeface(typeface);
    textView.setText(text, TextView.BufferType.SPANNABLE);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(deviceWidth, View.MeasureSpec.AT_MOST);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(widthMeasureSpec, heightMeasureSpec);
    return textView.getMeasuredHeight();
}
 
开发者ID:Break369,项目名称:MyLife,代码行数:22,代码来源:TextViewUtils.java

示例14: showInfoGame

import android.widget.TextView; //导入方法依赖的package包/类
public void showInfoGame(GridView layout) {
    int colWidth = 0;

    if (getCount() > 0) {
        // Use the first item to measure the column width
        TextView tempView = createTextView(getItem(0));
        tempView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        tempView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        colWidth = tempView.getMeasuredWidth();
    }
    layout.setColumnWidth(colWidth);
    layout.requestLayout();
}
 
开发者ID:dftec-es,项目名称:planetcon,代码行数:14,代码来源:TextAdapter.java

示例15: setup

import android.widget.TextView; //导入方法依赖的package包/类
@Before
public void setup() {
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }

    context = InstrumentationRegistry.getTargetContext();
    recyclerView = mock(RecyclerView.class);
    adapter = mock(BrickRecyclerAdapter.class);
    view = mock(View.class);
    dataManager = mock(BrickDataManager.class);

    when(dataManager.getBrickRecyclerAdapter()).thenReturn(adapter);
    when(adapter.getRecyclerView()).thenReturn(recyclerView);

    footerBehavior = spy(new TestStickyFooterBehavior(dataManager));

    itemView = new TextView(context);
    ((TextView) itemView).setText(TEST);
    itemView.measure(MOCK_VIEW_SIZE, MOCK_VIEW_SIZE);
    stickyViewHolder = new BrickViewHolder(itemView);

    stickyContainer = spy((ViewGroup) LayoutInflater.from(context).inflate(R.layout.vertical_footer, new LinearLayout(context), false));
    stickyContainer.layout(0, 0, MOCK_VIEW_SIZE, MOCK_VIEW_SIZE);
    stickyContainer.setLayoutParams(new ViewGroup.LayoutParams(MOCK_VIEW_SIZE, MOCK_VIEW_SIZE));

    stickyHolderLayout = spy((ViewGroup) LayoutInflater.from(context).inflate(R.layout.text_brick, new LinearLayout(context), false));
    stickyHolderLayout.layout(0, 0, MOCK_VIEW_SIZE, MOCK_VIEW_SIZE);
    stickyHolderLayout.setLayoutParams(new ViewGroup.LayoutParams(MOCK_VIEW_SIZE, MOCK_VIEW_SIZE));

    footerBehavior = spy(new TestStickyFooterBehavior(dataManager, stickyContainer));
    footerBehavior.swapStickyView(stickyViewHolder);
    footerBehavior.translateStickyView();
}
 
开发者ID:wayfair,项目名称:brickkit-android,代码行数:35,代码来源:StickyFooterBehaviorTest.java


注:本文中的android.widget.TextView.measure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。