3
我想显示一个弹出窗口,显示我刚刚在GridView中单击的全屏图像。单击GridView项目时在PopupWindow中显示完整图像?
movieBrowser.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
popupWindow.showAtLocation(parent, Gravity.CENTER_VERTICAL);
ImageView fullImageView = (ImageView) findViewById(R.id.full_image);
fullImageView.setImageResource(mThumbIds[position]);
}
});
这里是图像适配器
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7
};
}
}
什么问题?你的代码的结果是什么,它与你想实现的有什么不同? – Ridcully
此代码无法运行fullImageView.setImageResource(mThumbsIds [positon]给出错误,我想要的是获取图像在GridView中的位置并将其传递给ImageView中的弹出布局,因此弹出完整图像。 – homi3kh
你应该编辑你的问题并在那里陈述这个问题,并且还会出现什么错误(最好添加LogCat消息的相关部分)如果你想让这里的人帮助你,你必须提供所有可能相关的东西。知道你的代码,没有人知道错误,没有人知道你想要达到什么,什么不工作,如果你没有尽可能清楚地告诉我们。 – Ridcully