Android ViewFlipper + 主屏动画

标签 android animation homescreen viewflipper

我正在尝试使用 ViewFlipper 并使其像主屏幕一样运行(布局将随您的手指移动)。 Check out this举个例子。我想使用仅包含两个子项的 ViewFlipper 来执行此操作,因此应根据用户移动手指的方式在当前 View 的任一侧显示相反的 View 。此代码有效,但一次仅适用于 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;
}

是否可以将其设置为在当前 View 的两侧显示相同的 View ?

最佳答案

谢谢 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 以尝试消除 View 的一些闪烁。这很有帮助,但我还是得到了一点。

关于Android ViewFlipper + 主屏动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2732153/

相关文章:

android - inflateMenu 在 CollapsingToolbarLayout 内的工具栏上不起作用

html - CSS3/HTML5 中的发光动画效果

javascript - 使用 velocity.js 为可拖动元素设置动画

android - 检测Android主屏幕的旋转

android - android小部件中的可编辑 TextView

java - 我可以直接从我的 Android 应用程序在 Google Play 中对不同的 Android 应用程序进行评分和发表评论吗?

android - 为平板电脑设计应用程序以支持不同的屏幕尺寸。

android - 通过 STREAM_ALARM 播放声音不会在 Marshmallow 中从头开始

css - 如何使 `react-beautiful-dnd` 不触发 `react-transition-group` 动画?

android - 从我的应用程序打开 android 自己的启动器