좋아요. ViewFlipper
에는 3 개의 LinearLayouts
이 중첩되어 있습니다. 기본적으로 첫 번째 것을 보여줍니다. 이 코드 :MotionEvent.ACTION_MOVE를 사용하여 홈 화면과 같은 ViewFlipper 만들기
// Assumptions in my Activity class:
// oldTouchValue is a float
// vf is my view flipper
@Override
public boolean onTouchEvent(MotionEvent touchEvent) {
switch (touchEvent.getAction()) {
case MotionEvent.ACTION_DOWN: {
oldTouchValue = touchEvent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchEvent.getX();
if (oldTouchValue < currentX) {
vf.setInAnimation(AnimationHelper.inFromLeftAnimation());
vf.setOutAnimation(AnimationHelper.outToRightAnimation());
vf.showNext();
}
if (oldTouchValue > currentX) {
vf.setInAnimation(AnimationHelper.inFromRightAnimation());
vf.setOutAnimation(AnimationHelper.outToLeftAnimation());
vf.showPrevious();
}
break;
}
case MotionEvent.ACTION_MOVE: {
// TODO: Some code to make the ViewFlipper
// act like the home screen.
break;
}
}
return false;
}
public static class AnimationHelper {
public static Animation inFromRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(350);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
public static Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(350);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
// for the next movement
public static Animation inFromLeftAnimation() {
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromLeft.setDuration(350);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
}
public static Animation outToRightAnimation() {
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setDuration(350);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
}
}
...보기가 뒤집기는하지만 애니메이션은 매우 "켜기/끄기"입니다. 나는 누군가가 마지막 부분으로 나를 도울 수 있는지 궁금해. LinearLayouts에 액세스 할 수 있다고 가정하면 deltaX 및 deltaY를 기반으로 레이아웃의 위치를 설정할 수있는 방법이 있습니까?
누군가 나에게 this link을 주었고이 작업을 수행하는 방법에 대한 힌트는 applyTransformation
방법을 참조해야한다고 말했지만이 같은 동작을 반복하는 방법을 모르겠습니다. 당신이 당신의 손가락이 쉽게 이루어집니다 이동하는 동안
좋아, 작품을! 나는 나머지 부분을 알아낼 수있다. 고마워. – DJTripleThreat