2013-06-12 97 views
0

目前我正在使用GalleryView並更改工作正常的圖像。GallaryView更改按鈕上的圖像單擊

但我想禁用滑動的GalleryView並更改按鈕點擊加載的圖像。 我如何實現此功能。

我現在的等級是如下提前

public class PopUpWindow extends Activity { 
TextView closebtn; 
Integer[] pics = { 
     R.drawable.account_icon, 
     R.drawable.coffee_icon, 
     R.drawable.help_icon, 
     R.drawable.menu_icon, 

}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setUpDialogProperties(); 
    this.setFinishOnTouchOutside(false); 
    setContentView(R.layout.pop_up_dialog); 
    fetchUI(); 

} 
private void fetchUI(){ 
    closebtn   =   (TextView)findViewById(R.id.okBtn); 
    closeDialog(); 
    Gallery ga = (Gallery)findViewById(R.id.Gallery01); 
     ga.setAdapter(new ImageAdapter(this)); 
     ga.setUnselectedAlpha(0.0f); 
} 

private void closeDialog(){ 
    closebtn.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
     finish(); 

     } 
    }); 
} 
private void setUpDialogProperties() { 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setBackgroundDrawableResource(android.R.color.transparent); 
     android.view.WindowManager.LayoutParams lp = getWindow() 
     .getAttributes(); 
     lp.gravity = Gravity.BOTTOM; 
     getWindow().setAttributes(lp); 

    } 
public class ImageAdapter extends BaseAdapter { 

     private Context ctx; 
     int imageBackground; 

     public ImageAdapter(Context c) { 
      ctx = c; 
      TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1); 
      imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1); 
      ta.recycle(); 
     } 

     @Override 
     public int getCount() { 

      return pics.length; 
     } 

     @Override 
     public Object getItem(int arg0) { 

      return arg0; 
     } 

     @Override 
     public long getItemId(int arg0) { 

      return arg0; 
     } 

     @Override 
     public View getView(int arg0, View arg1, ViewGroup arg2) { 
      ImageView iv = new ImageView(ctx); 
      iv.setImageResource(pics[arg0]); 
      iv.setScaleType(ImageView.ScaleType.FIT_CENTER); 
      iv.setLayoutParams(new Gallery.LayoutParams(150,150)); 
      iv.setBackgroundResource(imageBackground); 
      return iv; 
     } 

    } 

感謝

回答

0
case R.id.leftButton: 
     int position = mGallery.getSelectedItemPosition() - 1; 
     if (position < 0) 
      return; 
     mGallery.setSelection(position); 
     break; 
    case R.id.rightButton: 
     position = mGallery.getSelectedItemPosition() + 1; 
     if (position >= mGallery.getCount()) 
      return; 
     mGallery.setSelection(position); 
     break; 

我將設置的onclick你的下一個和上一個按鈕

+0

如何在這種情況下禁用畫廊刷卡視圖? –

+0

你必須重寫圖庫的onTouchListener並始終返回true – Blackbelt

+0

但我在這種情況下使用Base Adapter如何處理? –