2014-07-17 2 views
1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="center" 
android:orientation="vertical" 
android:weightSum="3" > 

<TextView 
    android:id="@+id/info" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ellipsize="end" 
    android:gravity="bottom|center" 
    android:maxLines="10" 
    android:scrollbars="vertical" 
    android:text="@string/hello_world" 
    android:textSize="20sp" /> 

<SeekBar 
    android:id="@+id/seek_bar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 

TextView와 검색 바를 설정 한 다음, 값이 바뀔 때마다 텍스트 줄에 텍스트 줄을 추가하도록 seekbar 수신기를 설정합니다. 텍스트보기가 점점 더 많은 텍스트를 얻고 앱이 완전히 느려지므로 maxlines이나 줄임표 같은 것을 사용하여 텍스트를 자르지 만, 작동하지 않는 것처럼 보입니다.Android에서 TextView의 텍스트 줄 수를 제한하는 방법은 무엇입니까?

사용할 수있는 빌드가 있습니까?

this.seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 

     @Override 
     public void onStopTrackingTouch(SeekBar seekBar) { 
      // TODO Auto-generated method stub 
      info.append("\n" + "Stop" + "Current: " + seekBar.getProgress()); 
     } 

     @Override 
     public void onStartTrackingTouch(SeekBar seekBar) { 
      // TODO Auto-generated method stub 
      info.append("\n" + "Start" + "Current: " + seekBar.getProgress()); 
     } 

     @Override 
     public void onProgressChanged(SeekBar seekBar, int progress, 
       boolean fromUser) { 
      // TODO Auto-generated method stub 
      info.append("\n" + "Changing" + "Current: " + seekBar.getProgress()); 
     } 
    }); 
+0

어쩌면 당신의 문자열입니다 길이가 너무 깁니다. 도움이 될 수있는 문자열의 길이를 설정하려고하면 제한된 길이의 로딩에 소요되는 시간이 줄어 듭니다. – Amsheer

+0

고마워요, 너무 길다는 뜻인가요? 예, 동의합니다. 안드로이드 빌드를 제한하고 싶습니다. – igonejack

+0

길이가 너무 길다는 것을 의미합니다. 최대 라인을 설정하는 일반적인 방법은 android : maxLines = "10"입니다. 당신이 사용하고 있습니다. 작동하지 않으면 문자열 한계를 설정하십시오. 나는 완벽한 해결책이 아니라는 의견을 말하고 있습니다. Thjanks. – Amsheer

답변

0

아마 당신이 무게 "1"을 사용하고 있다는 사실은 당신이 원하는 고정 된 크기와 충돌 : 여기

는 자바 코드입니다. 높이 값으로 "wrap_content"를 사용해 보시기 바랍니다.

호프가 문제를 해결할 수 있기를 바랍니다.

편집 :

이 링크를 따라이 사람에 의해 제공되는 솔루션을 구현하려고 : D
토론에서 하나와 텍스트 뷰를 교체합니다.

android ellipsize multiline textview

이 당신을 위해 무엇을 찾고있는 것 같다.

+0

고맙지 만 아직 작동하지 않는 것 같습니다 : ( – igonejack

+0

전체 XML을 추가 할 수 있습니까? – AlexBalo

+0

자, 이제 넣어주세요. – igonejack

0
final int maxLength = 50; 
    String mLongText = "I am very long sentence, but allowed maximum length is 50, trim me if I am more than 50chars"; 
    if(mLongText!="" && mLongText.length() > maxLength) 
    { 
     mLongText = mLongText.substring(0, maxLength); 
    } 
    mTextView.setText(mLongText); 

편집 :

당신은mTextView.setMaxLines(10);에 의해 라인의 최대 수를 설정할 수 있습니다. 최대 값은 행으로 표시됩니다. In xml android:maxLines="10"

android:ellipsize="end"...을 마지막에 추가했습니다.

EX가 : ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ...

android:ellipsize="start"으로 표시됩니다이 예제는 3 선에 대한 텍스트를 잘라 ...QRSTUVWXYZ

Refer this to get more info

+0

길이 제한이 아닐까요? 길이가 아니라 – igonejack

+0

@igonejack 업데이트 답변 – VenomVendor

+0

텍스트 뷰에 텍스트를 약 10 개만 넣고 싶습니다. 선이 있고 이전 선은 트렁크가됩니다. – igonejack

0

으로 표시됩니다 최대가

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); 
     } 

    } 
}); 
관련 문제