在Android中垂直查看寻呼机动画

在Android中垂直查看寻呼机动画,第1张

概述我是 android的新手,我试图实现垂直视图寻呼机与缩小页面变换器我的垂直视图寻呼机工作正常,当我来缩小页面变换器它将水平滚动,它不是垂直滚动 我的垂直视图分页器类 VerticalViewPager.class public class VerticalViewPager extends ViewPager {public VerticalViewPager(Context context) 我是 android的新手,我试图实现垂直视图寻呼机与缩小页面变换器我的垂直视图寻呼机工作正常,当我来缩小页面变换器它将水平滚动,它不是垂直滚动

我的垂直视图分页器类
VerticalVIEwPager.class

public class VerticalVIEwPager extends VIEwPager {public VerticalVIEwPager(Context context) {    super(context);    init();}public VerticalVIEwPager(Context context,AttributeSet attrs) {    super(context,attrs);    init();}private voID init() {    // The majority of the magic happens here    setPagetransformer(true,new VerticalPagetransformer());    // The easIEst way to get rID of the overscroll drawing that happens on the left and right    setoverScrollMode(OVER_SCRolL_NEVER);}private class VerticalPagetransformer implements VIEwPager.Pagetransformer {    @OverrIDe    public voID transformPage(VIEw vIEw,float position) {        if (position < -1) { // [-Infinity,-1)            // This page is way off-screen to the left.            vIEw.setAlpha(0);        } else if (position <= 1) { // [-1,1]            vIEw.setAlpha(1);            // Counteract the default slIDe Transition            vIEw.setTranslationX(vIEw.getWIDth() * -position);            //set Y position to swipe in from top            float yposition = position * vIEw.getHeight();            vIEw.setTranslationY(yposition);        } else { // (1,+Infinity]            // This page is way off-screen to the right.            vIEw.setAlpha(0);        }    }}/** * Swaps the X and Y coordinates of your touch event. */private MotionEvent swapXY(MotionEvent ev) {    float wIDth = getWIDth();    float height = getHeight();    float newX = (ev.getY() / height) * wIDth;    float newY = (ev.getX() / wIDth) * height;    ev.setLocation(newX,newY);    return ev;}@OverrIDepublic boolean onIntercepttouchEvent(MotionEvent ev){    boolean intercepted = super.onIntercepttouchEvent(swapXY(ev));    swapXY(ev); // return touch coordinates to original reference frame for any child vIEws    return intercepted;}@OverrIDepublic boolean ontouchEvent(MotionEvent ev) {    return super.ontouchEvent(swapXY(ev));}}

我的缩小动画
AnimationVIEwPager.class

public class AnimationVIEwPager implements VerticalVIEwPager.Pagetransformer {private static final float MIN_SCALE = 0.75f;public voID transformPage(VIEw vIEw,float position) {    int pageWIDth = vIEw.getWIDth();    if (position < -1) { // [-Infinity,-1)        // This page is way off-screen to the left.        vIEw.setAlpha(0);    } else if (position <= 0) { // [-1,0]        // Use the default slIDe Transition when moving to the left page        vIEw.setAlpha(1);        vIEw.setTranslationX(0);        vIEw.setScaleX(1);        vIEw.setScaleY(1);    } else if (position <= 1) { // (0,1]        // Fade the page out.        vIEw.setAlpha(1 - position);        // Counteract the default slIDe Transition        vIEw.setTranslationX(pageWIDth * -position);        // Scale the page down (between MIN_SCALE and 1)        float scaleFactor = MIN_SCALE                + (1 - MIN_SCALE) * (1 - Math.abs(position));        vIEw.setScaleX(scaleFactor);        vIEw.setScaleY(scaleFactor);    } else { // (1,+Infinity]        // This page is way off-screen to the right.        vIEw.setAlpha(0);    }}}

在这里我的样本图片我想要这样,请任何人帮我如何得到这个

解决方法 首先使用这个lib.它是开箱即用的最大壁橱,
链接如下
 github.com/castorflex/VerticalVIEwPager

然后创建一个新类

public class DepthPagetransformer implements VIEwPager.Pagetransformer {private static final float MIN_SCALE = 0.75f;public voID transformPage(VIEw vIEw,0]        // Use the default slIDe Transition when moving to the left page        vIEw.setAlpha(1);        vIEw.setTranslationX(0);        vIEw.setScaleX(1);        vIEw.setScaleY(1);    } else if (position <= 1) { // (0,1]        // Fade the page out.        vIEw.setAlpha(1 - position);        // Counteract the default slIDe Transition        vIEw.setTranslationX(pageWIDth * -position);        // Scale the page down (between MIN_SCALE and 1)        float scaleFactor = MIN_SCALE                + (1 - MIN_SCALE) * (1 - Math.abs(position));        vIEw.setScaleX(scaleFactor);        vIEw.setScaleY(scaleFactor);    } else { // (1,+Infinity]        // This page is way off-screen to the right.        vIEw.setAlpha(0);    }}}

在你的mainactivity类中,像这样在verticalvIEwpager类上设置动画

verticalVIEwPager=(VerticalVIEwPager)findVIEwByID(R.ID.verticalvIEw);     verticalVIEwPager.setPagetransformer(false,new DepthPagetransformer());     verticalVIEwPager.setAdapter(pager);

就是这样,谢谢你,请评价我的答案:)

总结

以上是内存溢出为你收集整理的在Android中垂直查看寻呼机动画全部内容,希望文章能够帮你解决在Android中垂直查看寻呼机动画所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1127979.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存