當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。