本文整理了Java中android.widget.TextView.getViewTreeObserver()
方法的一些代码示例,展示了TextView.getViewTreeObserver()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.getViewTreeObserver()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:getViewTreeObserver
暂无
代码示例来源:origin: stackoverflow.com
final TextView tv = (TextView)findViewById(R.id.image_test);
ViewTreeObserver vto = tv.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
LayerDrawable ld = (LayerDrawable)tv.getBackground();
ld.setLayerInset(1, 0, tv.getHeight() / 2, 0, 0);
ViewTreeObserver obs = tv.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
}
}
});
代码示例来源:origin: stackoverflow.com
TextView textView = (TextView)findViewById(R.id.my_textview);
ViewTreeObserver observer = textView.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//in here, place the code that requires you to know the dimensions.
//this will be called as the layout is finished, prior to displaying.
}
}
代码示例来源:origin: akexorcist/Android-RoundCornerProgressBar
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
tvProgress.getViewTreeObserver().removeOnGlobalLayoutListener(this);
else
tvProgress.getViewTreeObserver().removeGlobalOnLayoutListener(this);
drawTextProgressPosition();
}
代码示例来源:origin: stackoverflow.com
final TextView tv = (TextView)findViewById(R.id.venueLabel);
final ViewTreeObserver observer= tv.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
tv.getHeight()
observer.removeGlobalOnLayoutListener(this);
}
});
代码示例来源:origin: stackoverflow.com
final TextView tv = (TextView)findViewById(R.id.image_test);
ViewTreeObserver vto = tv.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
LayerDrawable ld = (LayerDrawable)tv.getBackground();
ld.setLayerInset(1, 0, tv.getHeight() / 2, 0, 0);
}
});
代码示例来源:origin: akexorcist/Android-RoundCornerProgressBar
@Override
protected void initView() {
tvProgress = (TextView) findViewById(R.id.tv_progress);
tvProgress.getViewTreeObserver().addOnGlobalLayoutListener(this);
}
代码示例来源: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: 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: stackoverflow.com
final TextView tv = (TextView)findViewById(R.id.image_test);
ViewTreeObserver vto = tv.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
LayerDrawable ld = (LayerDrawable)tv.getBackground();
ld.setLayerInset(1, 0, tv.getHeight() / 2, 0, 0);
}
});
代码示例来源:origin: fython/MaterialStepperView
mTitleText.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
代码示例来源:origin: stackoverflow.com
setContentView(R.layout.activity_editor);
mTextEditor = (TextView) findViewById(R.id.text_editor);
mTextEditor.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
代码示例来源: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: Naoki2015/CircleDemo
public void setText(final CharSequence content){
contentText.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@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;
}
});
contentText.setText(content);
contentText.setMovementMethod(new CircleMovementMethod(getResources().getColor(R.color.name_selector_color)));
}
代码示例来源:origin: stackoverflow.com
mTextView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mTextView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
mTextView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
代码示例来源:origin: AAkira/ExpandableLayout
@Override
public void onGlobalLayout() {
mExpandLayout.move(mOverlayText.getHeight(), 0, null);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mOverlayText.getViewTreeObserver().removeGlobalOnLayoutListener(mGlobalLayoutListener);
} else {
mOverlayText.getViewTreeObserver().removeOnGlobalLayoutListener(mGlobalLayoutListener);
}
}
};
代码示例来源:origin: stackoverflow.com
final TextView tv = (TextView) findViewById(R.id.myTextView);
ViewTreeObserver vto = tv.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Toast.makeText(MyActivity.this, tv.getWidth() + " x " + tv.getHeight(), Toast.LENGTH_LONG).show();
tv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
代码示例来源: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: GeekGhost/Ghost
public void setText(CharSequence charSequence) {
textContent = charSequence;
textView.setText(charSequence.toString());
ViewTreeObserver viewTreeObserver = textView.getViewTreeObserver();
viewTreeObserver.addOnPreDrawListener(new OnPreDrawListener() {
@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: AAkira/ExpandableLayout
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_read_more);
getSupportActionBar().setTitle(ExampleReadMoreActivity.class.getSimpleName());
mExpandButton = (Button) findViewById(R.id.expandButton);
mExpandLayout = (ExpandableRelativeLayout) findViewById(R.id.expandableLayout);
mOverlayText = (TextView) findViewById(R.id.overlayText);
mExpandButton.setOnClickListener(this);
mGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mExpandLayout.move(mOverlayText.getHeight(), 0, null);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mOverlayText.getViewTreeObserver().removeGlobalOnLayoutListener(mGlobalLayoutListener);
} else {
mOverlayText.getViewTreeObserver().removeOnGlobalLayoutListener(mGlobalLayoutListener);
}
}
};
mOverlayText.getViewTreeObserver().addOnGlobalLayoutListener(mGlobalLayoutListener);
}
代码示例来源:origin: githubwing/WingUE
@Override public void onGlobalLayout() {
mSearchBGTxt.getViewTreeObserver().removeOnGlobalLayoutListener(this);
performEnterAnimation();
}
});
内容来源于网络,如有侵权,请联系作者删除!