List of usage examples for android.widget TextView getMeasuredHeight
public final int getMeasuredHeight()
From source file:Main.java
public static void animateTextViewMaxLinesChange(final TextView textView, final int maxLines, final int duration) { final int startHeight = textView.getMeasuredHeight(); textView.setMaxLines(maxLines);/* w w w . java 2 s . c o m*/ textView.measure(View.MeasureSpec.makeMeasureSpec(textView.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); final int endHeight = textView.getMeasuredHeight(); ObjectAnimator animation = ObjectAnimator.ofInt(textView, MAX_HEIGHT_ATTR, startHeight, endHeight); animation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (textView.getMaxHeight() == endHeight) { textView.setMaxLines(maxLines); } } } ); animation.setDuration(duration).start(); }
From source file:Main.java
protected static Bitmap creatCodeBitmap(String contents, int width, int height, Context context) { TextView tv = new TextView(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); tv.setLayoutParams(layoutParams);//from ww w . ja va 2 s .co m tv.setText(contents); tv.setHeight(height); tv.setGravity(Gravity.CENTER_HORIZONTAL); tv.setWidth(width); tv.setDrawingCacheEnabled(true); tv.setTextColor(Color.BLACK); tv.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight()); tv.buildDrawingCache(); Bitmap bitmapCode = tv.getDrawingCache(); return bitmapCode; }
From source file:com.nma.util.sdcardtrac.SearchableActivity.java
public static int getTextHeight(Context context, CharSequence text, int textSize, int deviceWidth) { //, Typeface typeface,int padding) { TextView textView = new TextView(context); textView.setPadding(0, 0, 0, 0);/* w w w . j a v a 2s . c o m*/ textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); 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(); }
From source file:com.lgallardo.qbittorrentclient.TorrentDetailsFragment.java
/** * */*from w w w. j av a 2 s .c o m*/ * Method for Setting the Height of the ListView dynamically. Hack to fix * the issue of not showing all the items of the ListView when placed inside * a ScrollView * ** */ public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) return; int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED); int totalHeight = 0; View view = null; for (int i = 0; i < listAdapter.getCount(); i++) { long numOfLines = 1; view = listAdapter.getView(i, view, listView); if (i == 0) { view.setLayoutParams(new LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT)); } view.measure(desiredWidth, MeasureSpec.UNSPECIFIED); TextView file = (TextView) view.findViewById(R.id.file); TextView percentage = (TextView) view.findViewById(R.id.percentage); ProgressBar progressBar1 = (ProgressBar) view.findViewById(R.id.progressBar1); if (view.getMeasuredWidth() > desiredWidth) { double viewWidthLong = Double.valueOf(view.getMeasuredWidth()); double desiredWidthLong = Double.valueOf(desiredWidth); numOfLines = Math.round(viewWidthLong / desiredWidthLong) + 1; totalHeight += (file.getMeasuredHeight() * numOfLines) + percentage.getMeasuredHeight() + progressBar1.getMeasuredHeight(); } else { totalHeight += view.getMeasuredHeight(); } } LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); listView.requestLayout(); }
From source file:com.lgallardo.youtorrentcontroller.TorrentDetailsFragment.java
/** * */* w w w .j av a 2 s . c o m*/ * Method for Setting the Height of the ListView dynamically. Hack to fix * the issue of not showing all the items of the ListView when placed inside * a ScrollView * ** */ public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) return; int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED); int totalHeight = 0; View view = null; for (int i = 0; i < listAdapter.getCount(); i++) { long numOfLines = 1; view = listAdapter.getView(i, view, listView); if (i == 0) { view.setLayoutParams(new LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT)); } view.measure(desiredWidth, MeasureSpec.UNSPECIFIED); TextView file = (TextView) view.findViewById(R.id.file); TextView info = (TextView) view.findViewById(R.id.info); if (view.getMeasuredWidth() > desiredWidth) { double viewWidthLong = Double.valueOf(view.getMeasuredWidth()); double desiredWidthLong = Double.valueOf(desiredWidth); numOfLines = Math.round(viewWidthLong / desiredWidthLong) + 1; totalHeight += file.getMeasuredHeight() * numOfLines + info.getMeasuredHeight(); } else { totalHeight += view.getMeasuredHeight(); } } LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); listView.requestLayout(); }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java
private void layoutDebugInfo(final int positionInStrip, final ViewGroup placerView, final int x) { final TextView debugInfoView = mDebugInfoViews.get(positionInStrip); final CharSequence debugInfo = debugInfoView.getText(); if (debugInfo == null) { return;/*w ww.j av a 2 s. c o m*/ } placerView.addView(debugInfoView); debugInfoView.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); final int infoWidth = debugInfoView.getMeasuredWidth(); final int y = debugInfoView.getMeasuredHeight(); ViewLayoutUtils.placeViewAt(debugInfoView, x - infoWidth, y, infoWidth, debugInfoView.getMeasuredHeight()); }
From source file:com.gsbabil.antitaintdroid.UtilityFunctions.java
public int captureBitmapCache(String in) { TextView tv = (TextView) MyApp.context.findViewById(R.id.ocrTextview); String tvText = tv.getText().toString(); float tvTextSize = tv.getTextSize(); int tvColor = tv.getCurrentTextColor(); Bitmap bitmap = null;//from w ww .j av a 2s.c o m tv.setTextSize(36); tv.setTextColor(Color.CYAN); tv.setTypeface(Typeface.SANS_SERIF); tv.setText(in); while (bitmap == null) { // http://stackoverflow.com/questions/2339429/android-view-getdrawingcache-returns-null-only-null tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight()); tv.setDrawingCacheEnabled(true); tv.buildDrawingCache(true); bitmap = Bitmap.createBitmap(tv.getDrawingCache()); tv.destroyDrawingCache(); tv.setDrawingCacheEnabled(false); } FileOutputStream fos = null; int res = -1; try { fos = new FileOutputStream(currentDirectory() + "/files/" + MyApp.SCREENSHOT_FILENAME); if (fos != null) { bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos); fos.close(); res = 0; } } catch (Throwable e) { Log.i(MyApp.TAG, e.getMessage().toString()); res = -1; } tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTextSize); tv.setTypeface(Typeface.MONOSPACE); tv.setText(tvText); tv.setTextColor(tvColor); return res; }
From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java
private void setBasketListViewHeight() { final Point displaySize = UIUtils.getDisplaySize(mActivity); final TextView nameLbl = (TextView) mBasketDialog.findViewById(R.id.name); final ListView listView = (ListView) mBasketDialog.findViewById(R.id.list_view); final LinearLayout buttonContainer = (LinearLayout) mBasketDialog.findViewById(R.id.button_container); int maxPopupHeight = (int) Math.floor(displaySize.y * 0.75); nameLbl.measure(0, 0);//from w w w. j a v a 2 s. c om int nameLblHeight = nameLbl.getMeasuredHeight(); buttonContainer.measure(0, 0); int buttonContainerHeight = buttonContainer.getMeasuredHeight(); UIUtils.setListViewHeightBasedOnItems(listView, maxPopupHeight - nameLblHeight - buttonContainerHeight); }
From source file:com.miuhouse.yourcompany.student.view.widget.date.datepicker.DayPickerView.java
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { final TextView leftButton; final TextView rightButton; if (SUtils.isLayoutRtlCompat(this)) { leftButton = mNextButton;//from w w w .ja v a 2s . c o m rightButton = mPrevButton; } else { leftButton = mPrevButton; rightButton = mNextButton; } final int width = right - left; final int height = bottom - top; mViewPager.layout(0, 0, width, height); final SimpleMonthView monthView = (SimpleMonthView) mViewPager.getChildAt(0).findViewById(R.id.month_view); final int monthHeight = monthView.getMonthHeight(); // final int monthHeight = 0; final int cellWidth = monthView.getCellWidth(); // Vertically center the previous/next buttons within the month // header, horizontally center within the day cell. final int leftDW = leftButton.getMeasuredWidth(); final int leftDH = leftButton.getMeasuredHeight(); final int leftIconTop = monthView.getPaddingTop() + (monthHeight - leftDH) / 2; final int leftIconLeft = monthView.getPaddingLeft() + (cellWidth - leftDW) / 2; leftButton.layout(leftIconLeft, leftIconTop, leftIconLeft + leftDW, leftIconTop + leftDH); final int rightDW = rightButton.getMeasuredWidth(); final int tvResetDW = tvReset.getMeasuredWidth(); final int rightDH = rightButton.getMeasuredHeight(); final int tvResetDH = tvReset.getMeasuredHeight(); final int rightIconTop = monthView.getPaddingTop() + (monthHeight - rightDH) / 2; final int tvResetIconTop = monthView.getPaddingTop() + (monthHeight - tvResetDH) / 2; final int rightIconRight1 = width - monthView.getPaddingRight() - (cellWidth - rightDW) / 2 - 60; final int rightIconRight = leftIconLeft + 180; rightButton.layout(rightIconRight, rightIconTop, rightIconRight + rightDW, rightIconTop + rightDH); tvReset.layout(rightIconRight1 - tvResetDW, tvResetIconTop, rightIconRight1, tvResetIconTop + tvResetDH); }
From source file:com.air.mobilebrowser.BrowserActivity.java
/** Logs an onscreen message for debugging. */ public void logMessage(final TextView consoleView, String message, String value, int color) { if (mIsDebugEnabled && consoleView != null) { consoleView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override/*from w w w . j a va2 s . c o m*/ public void onFocusChange(View v, boolean hasFocus) { ViewParent parent = consoleView.getParent(); final ScrollView scroll = (ScrollView) parent; new Handler().postDelayed(new Runnable() { @Override public void run() { scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10); } }, 0); } }); Editable editable = consoleView.getEditableText(); SpannableString str = null; if (editable == null) { editable = new SpannableStringBuilder(); str = new SpannableString(message + ": " + value); str.setSpan(new ForegroundColorSpan(color), message.length() + 2, message.length() + 2 + value.length(), 0); } else { str = new SpannableString("\n" + message + ": " + value); str.setSpan(new ForegroundColorSpan(color), message.length() + 2, message.length() + 3 + value.length(), 0); } editable.append(str); consoleView.setText(editable, TextView.BufferType.EDITABLE); ViewParent parent = consoleView.getParent(); if (parent instanceof ScrollView) { final ScrollView scroll = (ScrollView) parent; new Handler().postDelayed(new Runnable() { @Override public void run() { scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10); } }, 1000); } } }