Gallery onKeyDown 按钮点击切换上一页下一页可以保留动画效果,但一些属性会使切换不

来自:http://www.eoeandroid.com/blog-136532-4536.html

 

切换:

prePage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, null);
}
});
nextPage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
}
});
}

如果在代码调用了gallery.setSpacing(2);这样的设置,会使prePage和nextPage中的onKeyDown失效。

如果想保留gallery.setSpacing( SPACING ),可以修改为
private static final int SPACING = 2;
prePage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dishGallery.onScroll(null, null, -1*(SPACING+1), 0);
dishGallery.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, null);
}
});
nextPage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dishGallery.onScroll(null, null, SPACING+1, 0);
dishGallery.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
}
});
}

你可能感兴趣的:(onKeyDown)