如何在选择项目时阻止Gallery
滚动?
到目前为止OnItemClickListener
对我来说是不成功的。
gal.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView parent, View v, int position, long id)
{
((ImageGallery) parent).setScrollingEnabled(false);
}
});
我已经将Gallery
public class ImageGallery extends Gallery
{
private boolean stuck = false;
public ImageGallery(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ImageGallery(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ImageGallery(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
return stuck || super.onTouchEvent(event);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_RIGHT:
return stuck || super.onKeyDown(keyCode, event);
}
return super.onKeyDown(keyCode, event);
}
public void setScrollingEnabled(boolean enabled)
{
stuck = !enabled;
}
}
答案 0 :(得分:1)
扩展库并覆盖onSingleTapUp方法,并使用performItemClick()方法为自定义实现执行click事件。