我有一个 2x5 的网格。网格中的每个元素都包含一个图像。当我长按图像时,我应该被带到画廊,在那里我可以在那里选择一张图片并将其分配给这个网格项目。这该怎么做?
问问题
375 次
1 回答
0
我认为您可以使用网格视图并将其与 View pager 结合使用。这是一个如何做到这一点的例子。
public class GridGallery extends BaseAdapter {
Context context;
public GridGallery(Context context) {
this.context = context;
}
@Override
public int getCount() {
return numberOfImages;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ImageView view;
if(convertView == null) {
view = new ImageView(context);
view.setScaleType(ImageView.ScaleType.FIT_CENTER);
view.setLayoutParams(new GridView.LayoutParams(screenWidth/4, screenHeight/4));
view.setAdjustViewBounds(false);
view.setPadding(2, 2, 2, 2);
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// You can set your View Pager adapter here
//
return false;
}
});
if(view!=null) {
// Here you can download your images from internet.
thumbnailLoader.DisplayImage(urlList.get(position), view);
notifyDataSetChanged(); //Calling this helped to solve the problem.
view.setTag(position);
}
return view;
}
}
于 2012-05-29T06:43:20.223 回答