2012-11-27 2 views
2

버튼에 텍스트를 스크롤하고 싶습니다 ... 그래서 이것을 위해 버튼에 텍스트보기를 사용하고 있습니다. 레이아웃에 다음 속성을 설정했습니다. 하지만 작동하지 않습니다. RelativeLayout에서 이것을 사용하고 있습니다 ... 누군가 내 코드에 무슨 문제가 있다고 말할 수 있습니까? 안드로이드, 가로 스크롤러가있는 텍스트보기

<TextView 
    android:id="@+id/textView1" 
    android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget" 
    android:layout_width="wrap_content" 
    android:singleLine="true" 
    android:ellipsize="marquee" 
    android:marqueeRepeatLimit ="marquee_forever" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:scrollHorizontally="true" 
    android:layout_height="wrap_content"/> 

내가 솔루션을 가지고 그리고 난이 공유하고 ... 난 layout.xml 파일에 다음 클래스

import android.content.Context; 
import android.graphics.Rect; 
import android.util.AttributeSet; 
import android.widget.TextView; 

public class ScrollingTextView extends TextView { 

    public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public ScrollingTextView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public ScrollingTextView(Context context) { 
     super(context); 
    } 
    @Override 
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { 
     if(focused) 
      super.onFocusChanged(focused, direction, previouslyFocusedRect); 
    } 

    @Override 
    public void onWindowFocusChanged(boolean focused) { 
     if(focused) 
      super.onWindowFocusChanged(focused); 
    } 


    @Override 
    public boolean isFocused() { 
     return true; 
    } 

} 

내가 두 개 이상의 TextView가 화면에 스크롤 할 필요에 따라 ... 을 생성 ....이

<com.yourpackage.ScrollingTextView 
     android:id="@+id/TextView01" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     android:padding="5dip" 
     android:scrollHorizontally="true" 
     android:singleLine="true" 
     android:text="1.option" /> 

을 사용 봐라 .... 그것은 끝났어

+0

가능한 중복의 일을 볼라 텍스트 뷰를 만들기 위해이 클래스를 사용하여 두 개 이상의 textveiw에 스크롤이 필요로 텍스트 뷰를 확장하는 클래스를 확인 [줄임표 = "선택 윤곽"항상 스크롤 할 수있는 방법이 있습니까?] (http://stackoverflow.com/questions/1827751/is-there-a-way-to-make-ellipsize-marquee-always-scroll) – Sam

+0

나는이 문제의 해결책을 가지고 ..... –

답변

0

을 사용하면 TextView를 하위 클래스로 만들 필요가 없습니다.

TextView 
     android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget" 
     android:singleLine="true" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit ="marquee_forever" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:scrollHorizontally="true" 
     android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 



public class WordExtractTest extends Activity { 

    TextView tv1; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     tv1 = (TextView)findViewById(R.id.tv1); 

     loadDoc(); 
    } 

    private void loadDoc(){ 

     String s = ""; 

     for(int x=0;x<=100;x++){ 
      s += "Line: "+String.valueOf(x)+"\n"; 
     } 

     tv1.setMovementMethod(new ScrollingMovementMethod()); 

     tv1.setText(s); 

    } 
} 
0

당신이

import android.content.Context; 
import android.graphics.Rect; 
import android.util.AttributeSet; 
import android.widget.TextView; 

public class ScrollingTextView extends TextView { 

    public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public ScrollingTextView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 



    public ScrollingTextView(Context context) { 
     super(context); 
    } 
    @Override 
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { 
     if(focused) 
      super.onFocusChanged(focused, direction, previouslyFocusedRect); 
    } 

    @Override 
    public void onWindowFocusChanged(boolean focused) { 
     if(focused) 
      super.onWindowFocusChanged(focused); 
    } 


    @Override 
    public boolean isFocused() { 
     return true; 
    } 

} 

은 이제

<com.yourPackage.ScrollingTextView 
     android:id="@+id/TextView" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/button4" 
     android:layout_alignTop="@+id/button4" 
     android:layout_marginLeft="18dp" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     android:padding="5dip" 
     android:scrollHorizontally="true" 
     android:singleLine="true" 
     android:text="Text" 
     android:textColor="#000000" />