recyclerview 中的 cardview 阴影高程动画
cardview shadow elevation animation in recyclerview
我想要 cardview
elevation
动画,就像 Google 在 "PlayGames" 动画中所做的那样。这是动画示例 gif
。任何人都可以指导我如何做或参考任何图书馆。
谢谢
怎么做?
使用 Viewpager 和阴影变换
1- 为 cardview
创建一个 PagerAdapter
2- 在适配器内部 instantiateItem
方法中为卡片设置高度
CardView cardView = (CardView) view.findViewById(R.id.cardView);
if (mBaseElevation == 0) {
mBaseElevation = cardView.getCardElevation();
}
cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
mViews.set(position, cardView);
return view;
在那之后实施 ViewPager.OnPageChangeListener
onPageScrolled
里面
if (currentCard != null) {
if (mScalingEnabled) {
currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
}
currentCard.setCardElevation((baseElevation + baseElevation
* (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
}
CardView nextCard = mAdapter.getCardViewAt(nextPosition);
// We might be scrolling fast enough so that the next (or previous) card
// was already destroyed or a fragment might not have been created yet
if (nextCard != null) {
if (mScalingEnabled) {
nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
}
nextCard.setCardElevation((baseElevation + baseElevation
* (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
}
完整代码ViewPagerCards
如果您想使用 RecyclerView
你可以得到中间的项目并检查 onBindViewHolder
如果那个项目是中间的项目然后做缩放动画
知道得到中间检查这个答案:
我想要 cardview
elevation
动画,就像 Google 在 "PlayGames" 动画中所做的那样。这是动画示例 gif
。任何人都可以指导我如何做或参考任何图书馆。
谢谢
怎么做? 使用 Viewpager 和阴影变换
1- 为 cardview
创建一个PagerAdapter
2- 在适配器内部 instantiateItem
方法中为卡片设置高度
CardView cardView = (CardView) view.findViewById(R.id.cardView);
if (mBaseElevation == 0) {
mBaseElevation = cardView.getCardElevation();
}
cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
mViews.set(position, cardView);
return view;
在那之后实施 ViewPager.OnPageChangeListener
onPageScrolled
if (currentCard != null) {
if (mScalingEnabled) {
currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
}
currentCard.setCardElevation((baseElevation + baseElevation
* (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
}
CardView nextCard = mAdapter.getCardViewAt(nextPosition);
// We might be scrolling fast enough so that the next (or previous) card
// was already destroyed or a fragment might not have been created yet
if (nextCard != null) {
if (mScalingEnabled) {
nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
}
nextCard.setCardElevation((baseElevation + baseElevation
* (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
}
完整代码ViewPagerCards
如果您想使用 RecyclerView
你可以得到中间的项目并检查 onBindViewHolder
如果那个项目是中间的项目然后做缩放动画
知道得到中间检查这个答案: