NestedScrollView scroll down itself when content is fills

折月煮酒 提交于 2019-11-28 16:48:59

Try to set android:descendantFocusability="blocksDescendants" to the LinearLayout inside NestedScrollView. It works for me.

UPD: beware of using into the layout descendant elements like EditText, which should take a focus: that elements will not take a focus. If you know how to solve this, please let us to know.

An alternative to blocking the focus, is to add a new View that will steal the focus. Put it anywhere above the NestedScrollView, and it should work:

    <!--focusStealer, to avoid NestedScrollingView to scroll due to dynamically created views that take the focus-->
    <View
        android:layout_width="0px" android:layout_height="0px" android:focusable="true"
        android:focusableInTouchMode="true"/>

This working for me:

mNestedScrollViewChat.post(new Runnable(){
    @Override
    public void run(){
        mNestedScrollViewChat.fullScroll(View.FOCUS_DOWN);
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!