假设我点击了教育,我需要移动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());
}
});
}
答案 0 :(得分:1)
试试这个
your_scrollview.post(new Runnable() {
@Override
public void run() {
your_scrollview.scrollTo(0, yourview.getBottom());
}
});