我想基于[recyclerview
的更改来更改布局的背景图像。当我滚动recyclerview
时,在更改状态下,我想像https://www.pinterest.com/pin/860891284992684260/
这是我的代码:
//更新后的代码
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
int firstPos = HorizontalLayout.findFirstVisibleItemPosition();
int lastPos = HorizontalLayout.findLastVisibleItemPosition();
int middle = Math.abs(lastPos - firstPos) / 2 + firstPos;
View centerView = snapHelper.findSnapView(HorizontalLayout);
final int pos = HorizontalLayout.getPosition(centerView);
AllStories myStory = Stories.get(HorizontalLayout.getPosition(centerView));
// int selectedPos = -1;
for (int i = 0; i < RecyclerViewHorizontalAdapter.getItemCount(); i++) {
if (i == middle) {
if (myStory != null) {
if(dx>5)
{ background.setBackgroundResource(myStory.BackGroundImage);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1000);
AnimationSet animation = new AnimationSet(false); //change to false
animation.addAnimation(fadeOut);
background.setAnimation(animation);
}
background.setBackgroundResource(myStory.BackGroundImage);
//selectedPos = i;
LockStories(pos);
}
} else {
}
}
}
});
答案 0 :(得分:0)
更改图像时,请尝试使用fadeIn和fadeout动画。