2010-02-18 122 views
2

我已經在我的Android應用程序中使用幻燈片放映。除了我想滾動到滾動手勢上的下一個圖像(現在只是在減速之前滾動幾張圖像)之外,這種方法運行良好。我找不到合適的方法來做到這一點,我應該使用FrameLayout嗎?如何滾動到滾動手勢上的下一個(或上一個)圖像?Android Horizo​​ntalScrollView滾動頁

回答

2

從您的描述中,它聽起來像是現在您將幻燈片放映作爲scrollview中的一系列圖像實施,是正確的嗎?

與其將其放置在滾動視圖中並允許該視圖執行滾動操作,您可以顯示單個圖像並在圖像上聆聽圖像上的一個方塊或滾動手勢(請參閱documentation)。當您檢測到手勢時,您可以手動更改圖像。

如果您希望它爲進入屏幕的圖像設置動畫效果,您可以使用animation

+0

手勢文檔鏈接是不正確(http://www.govavi.com/locations.php?location_id=111&utm_source=league_welcome)你仍然有正確的鏈接? – ohhorob

+0

@ohhorob嘿,woops,對不起。我不確定鏈接應該指向什麼,但可能只是android文檔:http://developer.android.com/reference/android/view/View.OnTouchListener.html –

0

當你發佈一個問題你意識到答案的時刻!我從使用Gallery到Horizo​​ntalScrollView回到使用Gallery。只是顯示我的性格。畫廊很好地解決了我的問題。我有一個擴展Gallery的自定義類並覆蓋onFling(...)。在這裏根據方向將velocityX重置爲-300或300,這導致滾動到下一個「頁面」。

1

這是我最後使用

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, 
     float velocityY) { 
    // TODO Auto-generated method stub 

    if (velocityX <= 0){ 
     // hack - send event to simulate right key press 
     KeyEvent rightKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT); 
     this.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, rightKey); 

     rightKey = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_RIGHT); 
     this.onKeyUp(KeyEvent.KEYCODE_DPAD_RIGHT, rightKey);    

    }else{ 
     // hack - send event to simulate left key press 
     KeyEvent leftKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT); 
     this.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, leftKey); 

     leftKey = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_LEFT); 
     this.onKeyUp(KeyEvent.KEYCODE_DPAD_LEFT, leftKey); 
    } 


    // your callback activity if you have one: 
    if(callbackActivity != null){ 
     callbackActivity.didFlingGallery(); 
    } 

    return true; 
} 
+0

你應該選擇一個有效的回答你的問題,如果你認爲它的回答是正確的 –

相關問題