聚焦EditText时,Android EditText的容器(RecyclerView)自动滚动 [英] Android EditText's container (RecyclerView) auto scroll when EditText is Focused
问题描述
我得到了一个RecyclerView,其元素包含一个EditText小部件.
1.当前专注于第二个EditText,第一个EditText部分显示在屏幕上. 部分显示了第一个EditText
2.单击第一个EditText时,它会获得焦点,然后RecyclerView会自动向下滚动以完全显示第一个EditText. 当第一个EditText获得焦点时,RecyclerView会自动向下滚动
这很好,但是我想要的是RecyclerView不应自动滚动. 有什么办法吗? 谢谢!
实际上,您可以像这样控制RecycleView的滚动状态; </p>
创建您自己的LayoutManager并像这样覆盖scrollHorizontallyBy
.
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
int nScroll = 0;
// Do not let auto scroll
if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_SETTLING){
nScroll = super.scrollHorizontallyBy(dx, recycler, state);
}
}
那么SCROLL_STATE_SETTLING
是什么?
RecyclerView当前正在动画到最终位置,而没有 在外部控制之下.
I got a RecyclerView whose element contains a EditText widget.
1.currently focusing on the second EditText,the first EditText is partly showed on the screen. the first EditText is partly showed
2.when click the first EditText, it got focus, then RecyclerView would automatically scroll down to fully show the first EditText. RecyclerView automatically scroll down when first EditText got focused
This is great,but what I want is RecyclerView should not automatically scroll. Any solution? thanks!
Actually, there is a scroll state of RecycleView that you can control like this;
Create your own LayoutManager and override the scrollHorizontallyBy
like this.
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
int nScroll = 0;
// Do not let auto scroll
if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_SETTLING){
nScroll = super.scrollHorizontallyBy(dx, recycler, state);
}
}
So, what is the SCROLL_STATE_SETTLING
?
The RecyclerView is currently animating to a final position while not under outside control.
这篇关于聚焦EditText时,Android EditText的容器(RecyclerView)自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!