Android 如何在ViewPager中使用与ImageView不同的动画
我希望在ViewPager中的ImageView上进行缩放转换动画。只有ImageView应该具有ZoomOut动画,而ViewPager的其他元素应该具有默认动画。在您的活动中。 主代码位于ZoomOutPageTransformer查看Android 如何在ViewPager中使用与ImageView不同的动画,android,android-studio,android-layout,Android,Android Studio,Android Layout,我希望在ViewPager中的ImageView上进行缩放转换动画。只有ImageView应该具有ZoomOut动画,而ViewPager的其他元素应该具有默认动画。在您的活动中。 主代码位于ZoomOutPageTransformer查看transformPage()方法。(如果它回答了您的问号作为答案。谢谢) } 这是你的ZoomoutPage课程 public class ZoomOutPageTransformer implements ViewPager.PageTransformer
transformPage()
方法。(如果它回答了您的问号作为答案。谢谢)
}
这是你的ZoomoutPage课程
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.85f;
private static final float MIN_ALPHA = 0.5f;
public void transformPage(View CurentView, float position) {
ImageView view = (ImageView)CurrentView.findViewById(// the id of the image view you would like)
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);
} else if (position <= 1) { // [-1,1]
// Modify the default slide transition to shrink the page as well
float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
float vertMargin = pageHeight * (1 - scaleFactor) / 2;
float horzMargin = pageWidth * (1 - scaleFactor) / 2;
if (position < 0) {
view.setTranslationX(horzMargin - vertMargin / 2);
} else {
view.setTranslationX(-horzMargin + vertMargin / 2);
}
// Scale the page down (between MIN_SCALE and 1)
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);
// Fade the page relative to its size.
view.setAlpha(MIN_ALPHA +
(scaleFactor - MIN_SCALE) /
(1 - MIN_SCALE) * (1 - MIN_ALPHA));
} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
公共类ZoomoutPagetTransformer实现ViewPager.PageTransformer{
专用静态最终浮动最小刻度=0.85f;
专用静态最终浮动最小值α=0.5f;
公共页面(查看当前视图、浮动位置){
ImageView=(ImageView)CurrentView.findViewById(//您想要的图像视图的id)
int pageWidth=view.getWidth();
int pageHeight=view.getHeight();
if(位置<-1){/[-无穷大,-1)
//这个页面在屏幕的左边。
视图。setAlpha(0);
}否则,如果(位置)我想到了你提供给我的视差演示,我已经尝试过了,但没有得到预期的结果。@Declannadozie删除你的代码lemme modify,让我们看看你想要的和上面的链接完全一样吗?是的,我想要的是链接中显示的确切功能。@Declannadozie
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.85f;
private static final float MIN_ALPHA = 0.5f;
public void transformPage(View CurentView, float position) {
ImageView view = (ImageView)CurrentView.findViewById(// the id of the image view you would like)
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);
} else if (position <= 1) { // [-1,1]
// Modify the default slide transition to shrink the page as well
float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
float vertMargin = pageHeight * (1 - scaleFactor) / 2;
float horzMargin = pageWidth * (1 - scaleFactor) / 2;
if (position < 0) {
view.setTranslationX(horzMargin - vertMargin / 2);
} else {
view.setTranslationX(-horzMargin + vertMargin / 2);
}
// Scale the page down (between MIN_SCALE and 1)
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);
// Fade the page relative to its size.
view.setAlpha(MIN_ALPHA +
(scaleFactor - MIN_SCALE) /
(1 - MIN_SCALE) * (1 - MIN_ALPHA));
} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}