ScrollView 滚动时窃取焦点
我正在尝试制作一个聊天窗口。 屏幕上方有一个 TextView 包裹在 ScrollView 中;和屏幕底部的 EditText。 我使用以下代码使 ScrollView 在新消息消失时自动滚动。
scroll.post(new Runnable(){
@Override
public void run() {
scroll.fullScroll(View.FOCUS_DOWN);
}
});
令人烦恼的是,当 ScrollView 滚动时,它会从 EditText 中夺走我的焦点。 当 ScrollView 滚动时,我无法输入消息。 有人能给我一些启发吗?多谢 : )
I am trying to make a chatting window.
There's a TextView wrapped in a ScrollView in the upper side of the screen; and a EditText in the bottom of the screen.
I use following code to make the ScrollView scroll automatically when the new message is out of view.
scroll.post(new Runnable(){
@Override
public void run() {
scroll.fullScroll(View.FOCUS_DOWN);
}
});
Something annoying is when the ScrollView scrolls, it steals my focus from the EditText.
I can't input my message when the ScrollView is scrolling.
Can anybody give me some light? Thanks a lot : )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道一个解决方法。对应保持焦点的视图调用 requestFocus。
很高兴知道您是否以更好的方式解决了这个问题。
I know a workaround. Call requestFocus on the view that should keep the focus.
It would be nice to know if you solved it in a better way.