Android ViewFlipper主屏幕动画

Android ViewFlipper主屏幕动画,第1张

概述我正在尝试使用ViewFlipper并使其像主屏幕一样(布局将随您的手指移动).以Checkoutthis为例.我想用一个只包含两个子节点的ViewFlipper来做这个,所以相应的视图应该显示在当前视图的两侧,具体取决于用户移动手指的方式.此代码可以工作,但一次只能用于1个方向.这是在onTouchEvent中

我正在尝试使用VIEwFlipper并使其像主屏幕一样(布局将随您的手指移动).以Check out this为例.我想用一个只包含两个子节点的VIEwFlipper来做这个,所以相应的视图应该显示在当前视图的两侧,具体取决于用户移动手指的方式.此代码可以工作,但一次只能用于1个方向.这是在ontouchEvent中.

case MotionEvent.ACTION_MOVE: leftVIEw.setVisibility(VIEw.VISIBLE);rightVIEw.setVisibility(VIEw.VISIBLE);// move the current vIEw to the left or right.currentVIEw.layout((int) (touchEvent.getX() - oldtouchValue),    currentVIEw.gettop(),    (int) (touchEvent.getX() - oldtouchValue) + 320,    currentVIEw.getBottom());// place this vIEw just left of the currentVIEwleftVIEw.layout(currentVIEw.getleft() - 320, leftVIEw.gettop(),    currentVIEw.getleft(), leftVIEw.getBottom());// place this vIEw just right of the currentVIEwrightVIEw.layout(currentVIEw.getRight(), rightVIEw.gettop(),     currentVIEw.getRight() + 320, rightVIEw.getBottom());

我放在最后那个方向的底部两条线中的哪一条将正常工作但另一条不会.

以下是我设置leftVIEw和rightVIEw的方法:

final VIEw currentVIEw = myFlipper.getCurrentVIEw();final VIEw leftVIEw, rightVIEw;if (currentVIEw == meVIEw) {    Log.d("current layout: ", "me");    leftVIEw = youVIEw;    rightVIEw = youVIEw;} else if (currentVIEw == youVIEw) {    Log.d("current layout: ", "you");    leftVIEw = meVIEw;    rightVIEw = meVIEw;} else {    leftVIEw = null;    rightVIEw = null;}

是否可以设置它以便在当前视图的两侧显示相同的视图?

解决方法:

谢谢stealthcopter

如果有人感兴趣,那么这里有效的是新代码.

        if (touchEvent.getX() < oldtouchValue){             // place this vIEw just right of the currentVIEw            rightVIEw.layout(currentVIEw.getRight(), rightVIEw.gettop(),                             currentVIEw.getRight() + 320, rightVIEw.getBottom());        }else if (touchEvent.getX() > oldtouchValue) {            // place this vIEw just left of the currentVIEw            leftVIEw.layout(currentVIEw.getleft() - 320, leftVIEw.gettop(),                            currentVIEw.getleft(), leftVIEw.getBottom());        }

我还将setVisibility()调用移动到MotionEvent.ACTION_DOWN,试图摆脱视图的一些闪烁.这有帮助,但我仍然得到一点.

总结

以上是内存溢出为你收集整理的Android ViewFlipper主屏幕动画全部内容,希望文章能够帮你解决Android ViewFlipper主屏幕动画所遇到的程序开发问题。

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

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

原文地址:https://www.54852.com/web/1116780.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存