我想使用與iPhone畫廊效果相同的效果。即當我滾動圖像時,下一個圖像開始出現並相對於先前圖像向內移動。使用onScroll和viewFlipper
我想使用此視圖鰭狀肢,直到現在我可以移動第一個圖像,但我看不到下一個圖像。
public class IphoneAnimationActivity extends Activity implements
OnGestureListener {
private static final int SWIPE_THRESHOLD_VELOCITY = 1000;
GestureDetector gestureScanner;
ViewFlipper flipper;
View v;
ImageView imageView1;
ImageView imageView2;
LayoutInflater inflate;
Animation slideOutRight;
Animation slideInLeft;
Animation slideOutLeft;
Animation slideInRight;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
flipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
inflate = getLayoutInflater();
v = inflate.inflate(R.layout.image_view, null);
View x = v;
flipper.addView(x);
slideOutRight = AnimationUtils.loadAnimation(this,
R.anim.slide_right_out_photocards);
slideInRight = AnimationUtils.loadAnimation(this,
R.anim.slide_right_in_photocards);
slideOutLeft = AnimationUtils.loadAnimation(this,
R.anim.slide_left_out_photocards);
slideInLeft = AnimationUtils.loadAnimation(this,
R.anim.slide_left_in_photocards);
gestureScanner = new GestureDetector(this);
flipper.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return gestureScanner.onTouchEvent(event);
}
});
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// right to left swipe
if (e1.getX() - e2.getX() > 0
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
swipeLeft();
}
// left to right swipe
else if (e2.getX() - e1.getX() > 0
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
swipeRight();
}
return false;
}
private void swipeRight() {
flipper.setInAnimation(slideInRight);
flipper.setOutAnimation(slideOutRight);
View y = inflate.inflate(R.layout.image_view, null);
flipper.addView(y);
flipper.setDisplayedChild(1);
flipper.removeViewAt(0);
// flipper.showNext();
}
private void swipeLeft() {
flipper.setInAnimation(slideInLeft);
flipper.setOutAnimation(slideOutLeft);
View y = inflate.inflate(R.layout.image_view, null);
flipper.addView(y);
flipper.setDisplayedChild(1);
flipper.removeViewAt(0);
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
if((e1.getX() - e2.getX()) > 0)
{
flipper.scrollBy(10, 0);
return true;
}
else if ((e1.getX() - e2.getX()) < 0) {
flipper.scrollBy(-10, 0);
return true;
}
else
{
}
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
public boolean onTouchEvent(MotionEvent event) {
return gestureScanner.onTouchEvent(event);
}
}
我知道我可以使用它們,但我想用鰭狀肢作爲我當前的應用程序使用此並改變它帶畫廊在這一點上不是一個好主意。請給我一些建議 – Hardik4560