//这是我的Recyclerview onScrollEvent
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(final RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
final int positionView = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition();
if (dy > 0) {
if (positionView >= 3) {
final View view = recyclerView.getChildAt(3);
if (view != null && recyclerView.getChildAdapterPosition(view) == positionView) {
TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 200, 0);
translateAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
recyclerView.smoothScrollToPosition(positionView);
}
@Override
public void onAnimationEnd(Animation animation) {
view.clearAnimation();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
translateAnimation.setDuration(350);
view.setAnimation(translateAnimation);
}
createStackImageView();
for (int i = stackView.getChildCount()-1; i >=1; i--) {
ResizeAnimation resizeAnimation = new ResizeAnimation(stackView.getChildAt(i));
resizeAnimation.setHeights(stackView.getChildAt(i).getHeight(), stackView.getChildAt(i - 1).getHeight());
resizeAnimation.setWidths(stackView.getChildAt(i).getWidth(), stackView.getChildAt(i - 1).getWidth());
resizeAnimation.setDuration(250);
stackView.getChildAt(i).startAnimation(resizeAnimation);
if(i==1){
stackView.removeView(stackView.getChildAt(i));
stackView.invalidate();
stackView.requestLayout();
}
}
stackView.invalidate();
}
} else {
}
}
});
//这是我在relativelayout中创建一个imageview的方法
private void createStackImageView() {
fourthStack = new ImageView(getActivity());
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams
(1, 1);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
fourthStack.setLayoutParams(layoutParams);
fourthStack.setScaleType(ImageView.ScaleType.CENTER_CROP);
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
fourthStack.setBackgroundColor(color);
fourthStack.requestLayout();
stackView.addView(fourthStack, layoutParams);
}
现在我的主要问题是当RecyclerView滚动时我在底部创建图像以便动态堆栈数量。当在底部创建此ImageView时,应该删除RelativeLayout中的最顶层图像,这样就没有内存但是,对我而言,它正在删除我创建的整个堆栈。我无法弄清楚为什么会这样。
答案 0 :(得分:0)
当您从顶部移除ImageView时它可能与底部元素有相对连接。因此,当您从顶部删除图像时,与已删除视图的相对连接的视图将不可见。如果您使用GONE方法删除顶视图尝试使用Invisible并检查是否发生了同样的事情