private static int getMaxLines(TextView view) { int maxLines = -1; // No limit (Integer.MAX_VALUE also means no limit) TransformationMethod method = view.getTransformationMethod(); if (method != null && method instanceof SingleLineTransformationMethod) { maxLines = 1; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // setMaxLines() and getMaxLines() are only available on android-16+ maxLines = view.getMaxLines(); } return maxLines; }
private void cycleTextViewExpansion(TextView tv){ int collapsedMaxLines = 3; ObjectAnimator animation = ObjectAnimator.ofInt(tv, "maxLines", tv.getMaxLines() == collapsedMaxLines? tv.getLineCount() : collapsedMaxLines); animation.setDuration(200).start(); }
@TargetApi(JELLY_BEAN) public S hasMaxLines(int lines) { isNotNull(); int actualLines = actual.getMaxLines(); assertThat(actualLines) // .overridingErrorMessage("Expected maximum lines <%s> but was <%s>.", lines, actualLines) // .isEqualTo(lines); return myself; }
private static int getMaxLines(TextView view) { int maxLines = -1; // No limit (Integer.MAX_VALUE also means no limit) TransformationMethod method = view.getTransformationMethod(); if (method != null && method instanceof SingleLineTransformationMethod) { maxLines = 1; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // setMaxLines() and getMaxLines() are only available on android-16+ maxLines = view.getMaxLines(); } return maxLines; }
TextView myTextView = rootView.getViewById(R.id.my_text_view); if (myTextView.getLineCount() > myTextView.getMaxLines()) { // your code here }
@TargetApi(JELLY_BEAN) public S hasMaxLines(int lines) { isNotNull(); int actualLines = actual.getMaxLines(); assertThat(actualLines) // .overridingErrorMessage("Expected maximum lines <%s> but was <%s>.", lines, actualLines) // .isEqualTo(lines); return myself; }
public static float calculateTextSizeToFit(TextView textView, String desiredText, int limitSpSize, float desiredTxtPxSize) { Paint measurePaint = new Paint(textView.getPaint()); measurePaint.setTextSize(desiredTxtPxSize); float pWidth = measurePaint.measureText(desiredText); float labelWidth = textView.getWidth(); int maxLines = textView.getMaxLines(); while (labelWidth > 0 && pWidth/maxLines > labelWidth-20) { float textSize = measurePaint.getTextSize(); measurePaint.setTextSize(textSize-1); pWidth = measurePaint.measureText(desiredText); if (textSize < TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_SP, limitSpSize, textView.getContext().getResources().getDisplayMetrics())) break; } return measurePaint.getTextSize(); }
void collapseExpandTextView(TextView tv) { if (tv.getMaxLines() == MAX_LINE_COUNT) { ObjectAnimator animation = ObjectAnimator.ofInt(tv, "maxLines", tv.getMaxLines()); animation.setDuration(200).start();
private CardViewHolder(View view) { super(view); ButterKnife.bind(this, view); card.setOnClickListener((View clickedView) -> { if (Build.VERSION.SDK_INT >= 16) { cardDescription.setMaxLines(cardDescription.getMaxLines() == 3 ? Integer.MAX_VALUE : 3); } }); card.setOnLongClickListener((View draggedView) -> { // Create a new ClipData. // This is done in two steps to provide clarity. The convenience method // ClipData.newPlainText() can create a plain text ClipData in one step. // Create a new ClipData.Item from the ImageView object's tag ClipData dragData = ClipData.newPlainText("TEST", "TEST2"); // Starts the drag draggedView.startDrag(dragData, // the data to be dragged new View.DragShadowBuilder(draggedView), // the drag shadow builder draggedView, // no need to use local data 0 // flags (not currently used, set to 0) ); view.setVisibility(View.INVISIBLE); DeckLog.log("onLongClickListener"); return true; }); } }
values.put("LineSpacingExtra", tv.getLineSpacingExtra()); values.put("LineSpacingMultiplier", tv.getLineSpacingMultiplier()); values.put("MaxLines", tv.getMaxLines()); values.put("ShadowColor", getStringColor(tv.getShadowColor())); values.put("ShadowDX", tv.getShadowDx());