Android自动滚动EditText提示 [英] Android Auto Scrolling EditText Hint

查看:123
本文介绍了Android自动滚动EditText提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使编辑文本可滚动的问题

有人提到它不能通过singleLine = true滚动.

there is mentioned that it is not scrollable with singleLine=true.

所以我有2个选择:

  1. 我检查用户是否输入了"\ n"并将其删除,因此我也必须担心第二行中的内容.

  1. I check if the user inputs "\n" and delete that, then i have to worry about things in the second line, too.

我使用了一个自定义的textview,它会在一个循环中滚动,这是否也可以仅用于提示?

I use a custom textviews which scrolls through in a loop, could this be used here too only for the hint ?

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

}

我只是无法正确设置此格式.抱歉.

I just cant get this formated right. Sorry for that.

推荐答案

使EditText像这样可滚动:

Make your EditText Scrollable like this:

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

这篇关于Android自动滚动EditText提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆