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

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

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

TextView.scrollTo介绍

暂无

代码示例

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

TextView textView = (TextView) findViewById(R.id.text);
textView.setMovementMethod(new ScrollingMovementMethod());
final int lineNumber = 20
textView.post(new Runnable() {
  @Override
  public void run() {
    int y = textView.getLayout().getLineTop(lineNumber);
    textView.scrollTo(0, y);
  }
});

代码示例来源:origin: hibernate2011/RosClient

@Override
  public void run() {
    if(tvLog.getText().length() > 2000) {
      tvLog.setText("");
    }
    tvLog.setText(tvLog.getText() + "\ninfo:  " + event.msg + "\n");
    int offset=tvLog.getLineCount()*tvLog.getLineHeight();
    if(offset>tvLog.getHeight()){
      tvLog.scrollTo(0,offset-tvLog.getHeight());
    }
  }
});

代码示例来源:origin: baidu/speech-samples

private void scrollLog(String message) {
  Spannable colorMessage = new SpannableString(message + "\n");
  colorMessage.setSpan(new ForegroundColorSpan(0xff0000ff), 0, message.length(),
      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  mShowText.append(colorMessage);
  Layout layout = mShowText.getLayout();
  if (layout != null) {
    int scrollAmount = layout.getLineTop(mShowText.getLineCount()) - mShowText.getHeight();
    if (scrollAmount > 0) {
      mShowText.scrollTo(0, scrollAmount + mShowText.getCompoundPaddingBottom());
    } else {
      mShowText.scrollTo(0, 0);
    }
  }
}

代码示例来源:origin: gnaixx/dex-hdog

@Override
  public void handleMessage(Message msg) {
    super.handleMessage(msg);
    int what = msg.what;
    if (what == 0) {
      tvLog.append((String) msg.obj);
      int offset = tvLog.getLineCount() * tvLog.getLineHeight();
      if (offset - tvLog.getHeight() > 0) {
        tvLog.scrollTo(0, offset - tvLog.getHeight());
      }
    } else if (what == 1) {
      List<String> dumpeds = (List<String>) msg.obj;
      for (int i = 0; i < dumpeds.size(); i++) {
        String dumped = dumpeds.get(i);
        dumped = dumped.replaceAll(" ", "");
        tvResult.append(">>[" + (i+1) + "]<<" + dumped + "\n\n");
      }
    }
  }
};

代码示例来源:origin: Reone/Mrthumb

@Override
  public void handleMessage(Message msg) {
    switch (msg.what) {
      case FLAG_PLAYER_LOG:
        simpleActivity.tvPlayerLogArea.setText(msg.obj.toString());
        int offset1 = simpleActivity.tvPlayerLogArea.getLineCount() * simpleActivity.tvPlayerLogArea.getLineHeight();
        if (offset1 > simpleActivity.tvPlayerLogArea.getHeight()) {
          simpleActivity.tvPlayerLogArea.scrollTo(0, offset1 - simpleActivity.tvPlayerLogArea.getHeight());
        }
        break;
      case FLAG_THUMB_LOG:
        simpleActivity.tvThumbLogArea.setText(msg.obj.toString());
        int offset2 = simpleActivity.tvThumbLogArea.getLineCount() * simpleActivity.tvThumbLogArea.getLineHeight();
        if (offset2 > simpleActivity.tvThumbLogArea.getHeight()) {
          simpleActivity.tvThumbLogArea.scrollTo(0, offset2 - simpleActivity.tvThumbLogArea.getHeight());
        }
        break;
    }
  }
};

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

tv.scrollTo(0, scrollY);

代码示例来源:origin: derry/delion

/**
 * Show the end of the URL rather than the beginning.
 */
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
    int oldTop, int oldRight, int oldBottom) {
  Layout layout = mUrlBar.getLayout();
  if (layout == null) return;
  // Android doesn't account for the compound Drawable in its width calculations, leading to
  // improper scrolling and even Android improperly placing the horizontal fade in its
  // TextView calculation.  Get around it by calculating that width manually: crbug.com/303908
  int urlBarWidth = mUrlBar.getWidth();
  int iconWidth =
      mCurrentIconResource == 0 ? 0 : mIconResourceWidths.get(mCurrentIconResource);
  int availableTextWidth = urlBarWidth - iconWidth;
  int desiredWidth = (int) Layout.getDesiredWidth(layout.getText(), layout.getPaint());
  if (desiredWidth > availableTextWidth) {
    mUrlBar.scrollTo(desiredWidth - availableTextWidth, 0);
  } else {
    mUrlBar.scrollTo(0, 0);
  }
}

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

textView.scrollTo(0, 0);
return true;

相关文章

微信公众号

最新文章

更多

TextView类方法