目前我正在使用GalleryView并更改工作正常的图像。
但是我想禁用一下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 :(得分: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