0
我在我的活動中使用三個viewflippers,每個人都從服務器加載圖片。他們三人的動畫效果很好。重點是我也試圖刷他們每一個。我實現了一個手勢檢測,這裏是代碼:在瀏覽器上滑動衝突
package com.erc.AndroidViewFlipper;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;
public class AndroidViewFlipperActivity extends Activity {
ViewFlipper page,page2;
Animation animFlipInForeward;
Animation animFlipOutForeward;
Animation animFlipInBackward;
Animation animFlipOutBackward;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
page = (ViewFlipper)findViewById(R.id.flipper);
page2 = (ViewFlipper)findViewById(R.id.flipper2);
animFlipInForeward = AnimationUtils.loadAnimation(this, R.anim.flipin);
animFlipOutForeward = AnimationUtils.loadAnimation(this, R.anim.flipout);
animFlipInBackward = AnimationUtils.loadAnimation(this, R.anim.flipin_reverse);
animFlipOutBackward = AnimationUtils.loadAnimation(this, R.anim.flipout_reverse);
page.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.flipin));
page.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.flipout));
page.startFlipping();
page.setAutoStart(true);
page2.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.flipin));
page2.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.flipout));
page2.startFlipping();
page2.setAutoStart(true);
}
private void SwipeRight(){
page.setInAnimation(animFlipInBackward);
page.setOutAnimation(animFlipOutBackward);
page.showPrevious();
}
private void SwipeLeft(){
page.setInAnimation(animFlipInForeward);
page.setOutAnimation(animFlipOutForeward);
page.showNext();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return gestureDetector.onTouchEvent(event);
}
SimpleOnGestureListener simpleOnGestureListener
= new SimpleOnGestureListener(){
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
float sensitvity = 50;
if((e1.getX() - e2.getX()) > sensitvity){
SwipeLeft();
}else if((e2.getX() - e1.getX()) > sensitvity){
SwipeRight();
}
return true;
}
};
GestureDetector gestureDetector
= new GestureDetector(simpleOnGestureListener);
}
的問題是,無論我觸摸屏幕,第一viewflipper將刷卡。我想要的是,當我觸摸一個特定的視圖片時,只有被觸摸的片段會被滑動。請幫忙嗎?
我編輯了我的答案,但沒有解決問題 –
查看我更新的答案。 – cybersam
不幸的是,它沒有工作,我更新了我的代碼,我在你的答案中改變了唯一的事情是我在方法checkTouchedViewFlipper中初始化了vfRect(Rect vfRect = null)。我仍然無法滑動每個viewflipper –