我正在尝试使用 ViewFlipper 并使其像主屏幕一样(布局将随您的手指移动)。看看这个例子。我想使用仅包含两个子项的 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;
}
是否可以将其设置为在当前视图的两侧显示相同的视图?