安卓Textview的getLineCount返回0

ViewTreeObserver observer = tv.getViewTreeObserver(); // textAbstract为TextView控件  
            observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {  
  
                @Override  
                public void onGlobalLayout() {  
                    ViewTreeObserver obs = tv.getViewTreeObserver();  
                    obs.removeGlobalOnLayoutListener(this);  
                    if (tv.getLineCount() >= 2) {  
                        System.out.println("行数" + tv.getLineCount());  
                    }  
                }  
            });  

  

posted @ 2017-01-21 09:56  netcorner  阅读(1746)  评论(0编辑  收藏  举报