嗯,你可能不理解android:textIsSelectable已经实现了什么...
根据TextView
文档(你可以在这里找到它: here):
为了允许用户复制TextView
的某些或全部值并将其粘贴到其他地方,请将XML属性android:textIsSelectable
设置为true
或调用setTextIsSelectable(true)
.
textIsSelectable
标志允许用户在TextView
中进行选择手势,这反过来触发系统内置的复制/粘贴控件。
看起来滚动是isSelectable
标志的主要特点之一,但是...
根据问题,这里有一个帖子: How do I completely prevent a TextView from scrolling?
So I did a little research and I don't think it's as simple as just
disabling scrolling, but there are a few things you can do/try.
The first is setEnabled(false) but this will disable links and alter
the text color.
The second, which I suggest trying, is using the scrollTo(int x, int
y) method. Just scrollTo(0,0) after setting the text of the TextView,
my guess is the large text is the only thing causing the scrolling so
this should be able to take care of it.
The third answer I found that you can try is a bit more complicated
and not exactly your question but it may work for you can be found
here.
public class LinkMovementMethodOverride implements View.OnTouchListener{
@Override
public boolean onTouch(View v, MotionEvent event) {
TextView widget = (TextView) v;
Object text = widget.getText();
if (text instanceof Spanned) {
Spanned buffer = (Spanned) text;
int action = event.getAction();
if (action == MotionEvent.ACTION_UP
|| action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] link = buffer.getSpans(off, off,
ClickableSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
}
return true;
}
}
}
return false;
}
}
"After that apply it to the target textview as touch listener: -
textview.setOnTouchListener(new LinkMovementMethodOverride());"
您也可以尝试将这些行直接放入TextView属性中:
android:isScrollContainer="false"
android:ellipsize="end"
希望它有帮助。