NestedScrollView scroll down itself when content is fills
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);
}
});
This worked for me in Kotlin
nestedScrollView.post { nestedScrollView.fullScroll(View.FOCUS_DOWN) }