У меня есть RecyclerView с расширяемыми дочерними представлениями, когда нажимается дочерняя группа просмотра, она увеличивает количество представлений, анимирующих высоту группы просмотра, от 0 до измеренной высоты группы просмотра, например следующий gif:
Проблема в том, что я вызываю smoothScrollToPosition для recyclerView, он плавно прокручивается до позиции просмотра, но учитывает текущую высоту просмотра, которая все еще не расширена, в приведенном выше gif я касаюсь нижнего вида recyclerview, который не прокручивается до позиции, потому что вид уже виден, но когда я снова касаюсь (снова вызывая smoothscrolltoposition), он прокручивает вид до правильной позиции, потому что вид уже расширен.
Есть ли способ прокрутить вид в верхнюю часть экрана или просто прокрутить, чтобы сделать содержимое видимым?
Для справки: это метод, вызываемый для раздувания представлений:
collapsible_content.removeAllViews();
for(int i = 0; i < 5; i++) {
View link_view = getLayoutInflater().inflate(R.layout.list_item_timeline_step_link, collapsible_content, false);
TextView text = (TextView) link_view.findViewById(R.id.step_link_text);
text.setText("Test");
collapsible_content.addView(link_view);
}
И это мой метод расширения:
public void toggle() {
collapsible_content.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
Animation a;
if (mExpanded) {
a = new ExpandAnimation(collapsible_content.getLayoutParams().height, 0);
} else {
a = new ExpandAnimation(collapsible_content.getLayoutParams().height, getMeasuredHeight());
}
a.setDuration(mAnimationDuration);
collapsible_content.startAnimation(a);
mExpanded = !mExpanded;
}
И анимация:
private class ExpandAnimation extends Animation {
private final int mStartHeight;
private final int mDeltaHeight;
public ExpandAnimation(int startHeight, int endHeight) {
mStartHeight = startHeight;
mDeltaHeight = endHeight - startHeight;
}
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
final int newHeight = (int) (mStartHeight + mDeltaHeight *
interpolatedTime);
collapsible_content getLayoutParams().height = newHeight;
if (newHeight <= 0) {
collapsible_content setVisibility(View.GONE);
} else {
collapsible_content setVisibility(View.VISIBLE);
}
collapsible_content requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
}