2014-11-17 2 views
0

TextView은 5 행 이상인 경우 스크롤 할 수있게 만들었습니다. 이제 동적으로 내 Java 코드에서 동일한 TextView이 스크롤 할 수 있는지 또는 스크롤하여 스크롤 할 수 있는지 확인합니다. 스크롤 할 수 있으면 스크롤 할 수 있으므로보기 아래에보기를 변경할 수 있습니다. TextView를 스크롤 할 수 있는지 확인하는 방법

내가 시도 :

textView.setText(description); 
textView.setMovementMethod(new ScrollingMovementMethod()); 

if(textView.getLineCount() > 5) 
{ 
    view.setVisibility(View.VISIBLE); 
} 

하지만 textView.getLineCount() 또한 기능 canScrollHorizontally(int direction)을 시도했지만 구글의 문서는 내가 사용해야하는 매개 변수 말을하지 않는 0

과 같다.

+0

는 http://stackoverflow.com/a/12037459/2649012 –

+0

내가 텍스트 후 getLineCount()를 호출하고있어 – tvieira

+0

를 렌더링 http://stackoverflow.com/questions/3528790/textview-getlinecount-always-0-in-android 이것이 도움이 될 수도 있습니다 – enadun

답변

2

이 아닌 UI 스레드에서 결과를 가져 가도록 때문이다.

textView.post(new Runnable() { 

    @Override 
    public void run() { 

    int lineCount = textView.getLineCount(); 
    if(lineCount >=5) 
     textView.setVisibility(View.VISIBLE); 
    } 
}); 
+0

예. 나를 위해 만들어졌습니다. 나는 대답으로 게시 하겠지만 당신은 더 빨랐다;) – tvieira

+1

당신은 환영합니다 :) –

-1

lineCount를 얻기 위해 스레드를 사용하여 당신은 ZERO를 받고

@Override 
public void run() { 
    while(textView.getLineCount() == 0){ 
    } 
    textview_lineCount = textView.getLineCount(); 

} 
-1

TextViewScrollView의 자식 가정 시도하고 자동하려는이 추가하고 지금은 표시 할 수있는 것보다 더 많은 텍스트가 포함 된 후 TextView, 당신이 할 수 스크롤 다음

TextView t = (TextView) findViewById(R.id.someTextView); 
t.append("Some text"); 

ScrollView s; 
if (s.canScrollVertically(1)) { 
    logScroll(s); 
} 

private void logScroll(final ScrollView s) { 
    s.post(new Runnable() { 
     @Override 
     public void run() { 
      s.fullScroll(ScrollView.FOCUS_DOWN); 
     } 
    }); 
} 
관련 문제