如何从图库视图中禁用自动选择

时间:2013-07-15 08:22:00

标签: android android-gallery

我使用带图像的图库视图。我有以下onItemSelected -

public void onItemSelected(
        final AdapterView<?> parent,
        final View view,
        final int index,
        final long id) {



    GalleryAdapter.selected = index ;

      Animation growAnimation = AnimationUtils.loadAnimation(this,
              R.anim.grow_shrink_image);
      view.startAnimation(growAnimation);

     ...
}

它工作正常,当点击一个项目时,它移动到中心并运行动画。 但问题是,当向左或向右滚动时,到达中心的项目会自动选择并开始动画。如何禁用此自动选择?

1 个答案:

答案 0 :(得分:2)

我有同样的问题。所以我使用了setCallbackDuringFling()

此处gGalleryView的对象。

g.setCallbackDuringFling(false);

g.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> adapter, View view, int pos,
                    long arg3) {
                // TODO Auto-generated method stub
                Toast.makeText(MyActivity.this,"selected", 1000).show();
                            // here u can apply animation to selected image
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapter) {
                // TODO Auto-generated method stub

            }
        });