本文整理了Java中android.widget.TextView.getLayout()
方法的一些代码示例,展示了TextView.getLayout()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.getLayout()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:getLayout
暂无
代码示例来源: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: robolectric/robolectric
@Test
public void testInjection() {
Layout layout = mock(Layout.class);
when(textView.getLayout()).thenReturn(layout);
assertThat(textView.getLayout()).isSameAs(layout);
}
代码示例来源: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: nickbutcher/plaid
private TouchableUrlSpan getPressedSpan(TextView textView, Spannable spannable, MotionEvent
event) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= textView.getTotalPaddingLeft();
y -= textView.getTotalPaddingTop();
x += textView.getScrollX();
y += textView.getScrollY();
Layout layout = textView.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
TouchableUrlSpan[] link = spannable.getSpans(off, off, TouchableUrlSpan.class);
TouchableUrlSpan touchedSpan = null;
if (link.length > 0) {
touchedSpan = link[0];
}
return touchedSpan;
}
代码示例来源: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: stackoverflow.com
myTextView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
boolean ret = false;
CharSequence text = ((TextView) v).getText();
Spannable stext = Spannable.Factory.getInstance().newSpannable(text);
TextView widget = (TextView) v;
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] link = stext.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
}
ret = true;
}
}
return ret;
}
});
代码示例来源:origin: stackoverflow.com
public abstract class TextViewLinkHandler extends LinkMovementMethod {
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_UP)
return super.onTouchEvent(widget, buffer, event);
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);
if (link.length != 0) {
onLinkClick(link[0].getURL());
}
return true;
}
abstract public void onLinkClick(String url);
}
代码示例来源:origin: stackoverflow.com
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
代码示例来源:origin: hidroh/materialistic
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
代码示例来源:origin: stackoverflow.com
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
代码示例来源:origin: seven332/EhViewer
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
代码示例来源:origin: PrivacyApps/html-textview
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
代码示例来源:origin: jaydenxiao2016/AndroidFire
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
代码示例来源:origin: Naoki2015/CircleDemo
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
代码示例来源:origin: stackoverflow.com
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
代码示例来源:origin: wangdan/AisenWeiBo
@Override
public boolean onTouch(View v, MotionEvent event) {
Layout layout = ((TextView) v).getLayout();
代码示例来源:origin: seven332/EhViewer
private boolean action(int what, TextView widget, Spannable buffer) {
Layout layout = widget.getLayout();
代码示例来源: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: armcha/AutoLinkTextView
private TouchableSpan getPressedSpan(TextView textView, Spannable spannable, MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= textView.getTotalPaddingLeft();
y -= textView.getTotalPaddingTop();
x += textView.getScrollX();
y += textView.getScrollY();
Layout layout = textView.getLayout();
int verticalLine = layout.getLineForVertical(y);
int horizontalOffset = layout.getOffsetForHorizontal(verticalLine, x);
TouchableSpan[] link = spannable.getSpans(horizontalOffset, horizontalOffset, TouchableSpan.class);
TouchableSpan touchedSpan = null;
if (link.length > 0) {
touchedSpan = link[0];
}
return touchedSpan;
}
}
内容来源于网络,如有侵权,请联系作者删除!