目前我正在使用 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;
}
}
提前致谢