我希望cardview
elevation
动画就像谷歌在“PlayGames”动画中所做的那样。这是动画的gif
示例。任何人都可以指导我如何做或参考任何图书馆。
由于
答案 0 :(得分:1)
怎么做? 使用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
该项目是否为中间项目然后执行缩放动画
要知道中间检查这个答案:
Get center visible item of RecycleView when scrolling