假设我点击教育,我需要我的 NestedScrollView
移动,这样教育 CardView
应该与布局/屏幕的可见顶部对齐。
我尝试了 scrollView.smoothScrollTo(view.getTop());
就好像这个函数甚至没有被调用。
我调用 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());
}
});
}
最佳答案
试试这个
your_scrollview.post(new Runnable() {
@Override
public void run() {
your_scrollview.scrollTo(0, yourview.getBottom());
}
});
关于Android:在 NestedScrollView 中滚动以将 View 与可见屏幕顶部对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44942620/