Reputation: 1147
I have expandable views in my layout like this.
Suppose I click on education, I need my NestedScrollView
to move such that Education CardView
should align to visible top of layout/screen.
I tried scrollView.smoothScrollTo(view.getTop());
It's as if the function is not even getting called.
Code where I am calling smoothScrollTo()
@OnClick(R.id.ip_expand_experience)
void expandExperiences(){
if(!experiencesExpanded){
AnimationUtils.expand(experiencesCard,context,CARD_HEIGHT_COLLAPSED);
experiencesExpanded=true;
focusOnView(experiencesCard);
}else{
AnimationUtils.collapse(experiencesCard,context,CARD_HEIGHT_COLLAPSED);
experiencesExpanded=false;
}
}
private void focusOnView(final View view){
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.smoothScrollTo(0, view.getTop());
}
});
}
Upvotes: 1
Views: 851
Reputation: 69671
try this
your_scrollview.post(new Runnable() {
@Override
public void run() {
your_scrollview.scrollTo(0, yourview.getBottom());
}
});
Upvotes: 1