使 edittext 可滚动的问题 https://stackoverflow.com/questions/6250041/problem-with-making-edittext-scrollable
有人提到,当 singleLine=true 时,它是不可滚动的。
所以我有2个选择:
我检查用户是否输入“\n”并删除它,然后我也必须担心第二行中的事情。
-
我使用循环滚动的自定义文本视图,这也可以在这里仅用于提示吗?
<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;
}
}
我只是无法正确格式化。对此感到抱歉。
使您的 EditText 可滚动,如下所示:
EditText yourEditText = new EditText(context);
yourEditText.setScroller(new Scroller(context));
yourEditText.setMaxLines(1);
yourEditText.setVerticalScrollBarEnabled(true);
yourEditText.setMovementMethod(new ScrollingMovementMethod());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)