android.widget.TextView.getLineCount()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(347)

本文整理了Java中android.widget.TextView.getLineCount()方法的一些代码示例,展示了TextView.getLineCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.getLineCount()方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:getLineCount

TextView.getLineCount介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

private void cycleTextViewExpansion(TextView tv){
  int collapsedMaxLines = 3;
  ObjectAnimator animation = ObjectAnimator.ofInt(tv, "maxLines", 
    tv.getMaxLines() == collapsedMaxLines? tv.getLineCount() : collapsedMaxLines);
  animation.setDuration(200).start();
}

代码示例来源:origin: lingochamp/FileDownloader

private void updateDisplay(final CharSequence msg) {
  if (downloadMsgTv.getLineCount() > 2500) {
    downloadMsgTv.setText("");
  }
  downloadMsgTv.append(String.format("\n %s", msg));
  tipMsgTv.setText(String.format("%d/%d", finalCounts, totalCounts));
  if (needAuto2Bottom) {
    scrollView.post(scroll2Bottom);
  }
}

代码示例来源:origin: stackoverflow.com

TextView snippet;
snippet.setText("loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor ")
ViewTreeObserver vto = this.snippet.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

  @Override
  public void onGlobalLayout() {
    ViewTreeObserver obs = snippet.getViewTreeObserver();
    obs.removeGlobalOnLayoutListener(this);
    if (snippet.getLineCount() > 3) {
      int lineEndIndex = snippet.getLayout().getLineEnd(2);
      String text = snippet.getText().subSequence(0, lineEndIndex - 3) + "...";
      snippet.setText(text);
    }
  }
});

代码示例来源:origin: square/assertj-android

public S hasLineCount(int count) {
 isNotNull();
 int actualCount = actual.getLineCount();
 assertThat(actualCount) //
   .overridingErrorMessage("Expected line count <%s> but was <%s>.", count, actualCount) //
   .isEqualTo(count);
 return myself;
}

代码示例来源:origin: stackoverflow.com

final TextView tv_yourtext = (TextView)findViewById(R.id.text);
 tv_yourtext.setText("A really long text");
 ViewTreeObserver vto = tv_yourtext.getViewTreeObserver();
 vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
   @Override
   public void onGlobalLayout() {
     ViewTreeObserver obs = tv_yourtext.getViewTreeObserver();
     obs.removeGlobalOnLayoutListener(this);
     if(tv_yourtext.getLineCount() > 6){
       Log.d("","Line["+tv_yourtext.getLineCount()+"]"+tv_yourtext.getText());
       int lineEndIndex = tv_yourtext.getLayout().getLineEnd(5);
       String text = tv_yourtext.getText().subSequence(0, lineEndIndex-3)+"...";
       tv_yourtext.setText(text);
       Log.d("","NewText:"+text);
     }
   }
 });

代码示例来源:origin: Manabu-GT/ExpandableTextView

private static int getRealTextViewHeight(@NonNull TextView textView) {
  int textHeight = textView.getLayout().getLineTop(textView.getLineCount());
  int padding = textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom();
  return textHeight + padding;
}

代码示例来源:origin: Naoki2015/CircleDemo

@Override
public boolean onPreDraw() {
  // 避免重复监听
  contentText.getViewTreeObserver().removeOnPreDrawListener(this);
  int linCount = contentText.getLineCount();
  if(linCount > showLines){
    if(isExpand){
      contentText.setMaxLines(Integer.MAX_VALUE);
      textPlus.setText("收起");
    }else{
      contentText.setMaxLines(showLines);
      textPlus.setText("全文");
    }
    textPlus.setVisibility(View.VISIBLE);
  }else{
    textPlus.setVisibility(View.GONE);
  }
  //Log.d("onPreDraw", "onPreDraw...");
  //Log.d("onPreDraw", linCount + "");
  return true;
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 * 获取内容tv真实高度(含padding)
 * @param textView
 * @return
 */
private static int getRealTextViewHeight( TextView textView) {
  int textHeight = textView.getLayout().getLineTop(textView.getLineCount());
  int padding = textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom();
  return textHeight + padding;
}

代码示例来源:origin: Manabu-GT/ExpandableTextView

if (mTv.getLineCount() <= mMaxCollapsedLines) {
  return;

代码示例来源:origin: jaydenxiao2016/AndroidFire

if (mTvContent.getLineCount() <= mMaxCollapsedLines) {
  return;

代码示例来源:origin: hidroh/materialistic

@CallSuper
protected void bind(final VH holder, final Item item) {
  if (item == null) {
    return;
  }
  highlightUserItem(holder, item);
  decorateDead(holder, item);
  holder.mContentTextView.setLineSpacing(0f, mLineHeight);
  AppUtils.setTextWithLinks(holder.mContentTextView, item.getDisplayedText());
  Integer lineCount = mLineCounted.get(item.getId());
  if (lineCount != null && lineCount > 0) {
    toggleCollapsibleContent(holder, item, lineCount);
  } else {
    holder.mContentTextView.post(() -> {
      if (mContext == null) {
        return;
      }
      int count = holder.mContentTextView.getLineCount();
      mLineCounted.put(item.getId(), count);
      toggleCollapsibleContent(holder, item, count);
    });
  }
  bindActions(holder, item);
}

代码示例来源:origin: GeekGhost/Ghost

@Override
  public boolean onPreDraw() {
    if (!isInitTextView) {
      return true;
    }
    textLines = textView.getLineCount();
    isExpandNeeded = textLines > expandLines;
    isInitTextView = false;
    if (isExpandNeeded) {
      isShrink = true;
      doAnimation(textLines, expandLines, WHAT_ANIMATION_END);
    } else {
      isShrink = false;
      doNotExpand();
    }
    return true;
  }
});

代码示例来源:origin: stackoverflow.com

LayoutedTextView tv = new LayoutedTextView(context);
 tv.setOnLayoutListener(new OnLayoutListener() {
     @Override
     public void onLayouted(TextView view) {
         int lineCount = view.getLineCount();
         // do your work
     }
 });

代码示例来源:origin: stackoverflow.com

final TextView title = (TextView)findViewById(R.id.text);
   title.setText("A really long text");
   ViewTreeObserver vto = title.getViewTreeObserver();
   vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
     @Override
     public void onGlobalLayout() {
       ViewTreeObserver obs = title.getViewTreeObserver();
       obs.removeGlobalOnLayoutListener(this);
       if(title.getLineCount() > 3){
         Log.d("","Line["+title.getLineCount()+"]"+title.getText());
         int lineEndIndex = title.getLayout().getLineEnd(2);
         String text = title.getText().subSequence(0, lineEndIndex-3)+"...";
         title.setText(text);
         Log.d("","NewText:"+text);
       }
     }
   });

代码示例来源:origin: stackoverflow.com

TextView tv = (TextView) findViewById(R.id.TextView02);
int height_in_pixels = tv.getLineCount() * tv.getLineHeight(); //approx height text
tv.setHeight(height_in_pixels);

代码示例来源:origin: stackoverflow.com

MsgObject m = (MsgObject)getObject(position);
 TextView text=(TextView)vi.findViewById(R.id.text);
 ImageView image=(ImageView)vi.findViewById(R.id.image);
 text.setText(m.getMsg());
 text.getLineCount();
 imageLoader.DisplayImage(m.getData(), image);
 //Tag id is predefined in xml
 vi.setTag(R.id.listItemTag, m);
 return vi;

代码示例来源:origin: the-pig-of-jungle/smart-show

@Override
public void onViewAttachedToWindow(View v) {
  TextView msgView = (TextView) v;
  if (msgView.getLineCount() > 1) {
    msgView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
  } else {
    msgView.setGravity(Gravity.CENTER);
  }
}

代码示例来源:origin: stackoverflow.com

TextView tv;
Rect rc=new Rect();
//...
for(int i=0; i < tv.getLineCount(); i++)
{
  tv.getLineBounds(line, rc);
  Log.v(TAG, "Line #"+i+", left="+rc.left+", right="+rc.right);
}

代码示例来源:origin: AriesHoo/UIWidget

@Override
  public void run() {
    int lineCount = mTvMessage.getLineCount();
    if (lineCount > 1) {
      mTvMessage.setGravity(Gravity.LEFT | mTvMessage.getGravity());
    }
    if (mOnTextViewLineListener != null) {
      mOnTextViewLineListener.onTextViewLineListener(mTvMessage, lineCount);
    }
  }
});

代码示例来源:origin: whyalwaysmea/BigBoom

/**
 * 获取TextView真正的高度
 *
 * @param textView
 * @return
 */
private static int getRealTextViewHeight(@NonNull TextView textView) {
  int textHeight = textView.getLayout().getLineTop(textView.getLineCount());
  int padding = textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom();
  return textHeight + padding;
}

相关文章

TextView类方法