2012-07-07 58 views
0

problem with making edittext scrollableAndroid Auto Scrolling EditText提示

有人提到它不能用singleLine = true滾動。

所以,我有兩個選擇:

  1. 我檢查,如果用戶輸入「\ n」,並刪除這一點,那麼我擔心在第二行的事情了。

  2. 我使用自定義文本瀏覽器在循環中滾動,這也可以在這裏使用,只爲提示?

    <com.test.ScrollingTextView 
         android:id="@+id/textView1" 
         android:layout_width="wrap_content" 
         android:layout_height="fill_parent" 
         android:layout_marginTop="1dp" 
         android:layout_weight="0.17" 
         android:background="@color/black" 
         android:ellipsize="marquee" 
         android:gravity="center_vertical" 
         android:marqueeRepeatLimit="marquee_forever" 
         android:paddingLeft="10dp" 
         android:scrollHorizontally="true" 
         android:singleLine="true" 
         android:text="@string/editLength" 
         android:textAppearance="?android:attr/textAppearanceSmall" 
         android:textColor="@color/white" /> 
    

公共類ScrollingTextView擴展的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; 
} 

}

我只是不能得到這個格式化的權利。對不起。

回答

2

讓您的EditText滾動這樣的:

EditText yourEditText = new EditText(context); 
yourEditText.setScroller(new Scroller(context)); 
yourEditText.setMaxLines(1); 
yourEditText.setVerticalScrollBarEnabled(true); 
yourEditText.setMovementMethod(new ScrollingMovementMethod()); 
+0

yourEditText.setMaxLines(1);似乎沒有工作,被分成2行 – stefple 2012-07-07 10:02:58

+0

你想要水平滾動嗎? – rizzz86 2012-07-07 12:15:57

+0

我其實不想滾動它,id而是讓它自動滾動,就像我上面發佈的TextView一樣。 – stefple 2012-07-08 13:34:27