其他分享
首页 > 其他分享> > Android ViewFlipper主屏幕动画

Android ViewFlipper主屏幕动画

作者:互联网

我正在尝试使用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 currentView
leftView.layout(currentView.getLeft() - 320, leftView.getTop(),
    currentView.getLeft(), leftView.getBottom());

// place this view just right of the currentView
rightView.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,animation,homescreen,viewflipper
来源: https://codeday.me/bug/20190710/1422704.html