Java 安卓:OnGlobalLayout的问题
在我的代码中,我试图找到textview占据的高度Java 安卓:OnGlobalLayout的问题,java,android,textview,Java,Android,Textview,在我的代码中,我试图找到textview占据的高度 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); t = new TextView(this); ViewTreeObserver vto = t.getViewTreeObserver(); vto.addOnGlob
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t = new TextView(this);
ViewTreeObserver vto = t.getViewTreeObserver();
vto.addOnGlobalLayoutListener(this);
t.setText("This is to test the text\n Some Text \n Another ..");
t.append("\nafter something");
Toast.makeText(this, " The value at num = "+num,Toast.LENGTH_SHORT).show();
setContentView(t);
}
public void onGlobalLayout() {
// TODO Auto-generated method stub
num=t.getHeight();
Toast.makeText(this, "Hellooo !! height is "+num, Toast.LENGTH_SHORT).show();
}
onCreate()中num的值始终为零,但至少在onGlobalLayout()中,正确的高度存储在num中,但我无法使用它,因为它是应用程序的结尾。。
在应用程序的中间是否有可能获得文本长度?
如果上述问题中有任何错误,请原谅
谢谢,
Siva Kuamr这不是应用程序的结束,而是Android完成布局的时候。如果需要将其作为应用程序的“中间”,请调用将使用height值的方法。请参阅。这不是应用程序的结束,而是Android完成布局的时候。如果需要将其作为应用程序的“中间”,请调用将使用height值的方法。请参阅。有解决方案吗???有解决方案吗???