Android ViewFlipper +主屏幕动画
我正在尝试使用 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;
}
是否可以进行设置,以便在当前视图的两侧显示相同的视图?
I am trying to use a ViewFlipper and make it act like the home screen(The layout will move with your finger). Check out this for an example. I want to do this with a ViewFlipper that only contains two children so the opposite view should be shown on either side of the current view depending on which way the user moves their finger. This code works but only for 1 direction at a time. This is in 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());
Which ever of the bottom two lines I put last that direction will work correctly but the other will not.
Here is how I set the leftView and 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;
}
Is it going to be possible to set it up so that the same view is shown on both sides of the current view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
谢谢 Stealthcopter
如果有人感兴趣的话,这里的工作是新代码。
我还将 setVisibility() 调用移至 MotionEvent.ACTION_DOWN,试图消除视图的一些闪烁。这有帮助,但我仍然得到了一点。
Thanks stealthcopter
That worked here is the new code if anyone is interested.
I also moved the setVisibility() calls to the MotionEvent.ACTION_DOWN in an attempt to get rid of some flickering of the views. This helped but I still get a bit.
我可能没有很有建设性的建议,但如果你希望它表现得像主屏幕,为什么你不想看看 src ,并修改它满足您的需求?
I have possibly not very constructive suggestion, but if you want it to behave like a home screen, why you don't want to look at the src of that, and modify it to your needs ?
要消除闪烁,请在
MotionEvent.ACTION_DOWN
中设置setVisibility(View.INVISIBLE)
。视图上的默认值为“GONE”。这意味着在视图为“VISIBLE”或“INVISIBLE”之前,您无法在视图上设置 Layout()。因此,分三个步骤:To get rid of the flickering, set
setVisibility(View.INVISIBLE)
inMotionEvent.ACTION_DOWN
. The default value is "GONE" on a view. That means that you can not setLayout()
on a view until it's either "VISIBLE" or "INVISIBLE". So in three steps:如果我理解您的请求,现在应该使用 查看寻呼机
如下所示:
If I understand your request, this effect should now be implemented using a View Pager
Looks like this: