Android: Programmatically animate between images in Gallery widget

前端 未结 5 1405
鱼传尺愫
鱼传尺愫 2020-12-14 12:11

Note: As of Jellybean the gallery widget is deprecated. A ViewPager should be used instead.


I\'d like to programmatically move between images in the Gallery wi

5条回答
  •  自闭症患者
    2020-12-14 12:59

    Just call the key press handler for the gallery directly:

    public boolean onKeyDown(int keyCode, KeyEvent event)
    

    i.e

    Gallery gallery = ((Gallery) findViewById(R.id.gallery));
    
    gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, new KeyEvent(0, 0));
    

    One important thing - this solution works only if child that is on left/right was already created, which means that it has to be 'visible'. If you have your image on fullscreen - consider setting spacing to -1 value.

提交回复
热议问题