我在这里提供我的代码。我已将图像分成 9 个部分并在网格视图中显示如何通过单击它们来更改图像,即(第一个单击的图像应替换为第二个单击的图像,反之亦然)我使用了位图数组用于分割图像并将它们放置在网格视图中。那么如何通过单击两个图像来更改网格视图中的图像应该完成图像的交换,任何人都可以帮助我。
public class Imagepieces extends Activity {
ArrayList<Bitmap> breakedimages,duplicate;
GridView g;
int i=0,temp,temp2,rpos;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image);
breakedimages = getIntent().getParcelableArrayListExtra("breaked image");
duplicate = new ArrayList<Bitmap>(breakedimages);
Collections.shuffle(duplicate);
g = (GridView) findViewById(R.id.gridView1);
g.setAdapter(new CutAdapter(this, breakedimages));
g.setNumColumns((int) Math.sqrt(breakedimages.size()));
g.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
//=================================================
{
}
});
}
class CutAdapter extends BaseAdapter {
int iwidth, iheight;
Context context;
public CutAdapter(Imagepieces ipieces, ArrayList<Bitmap> breakedimages) {
// TODO Auto-generated constructor stub
iwidth = breakedimages.get(0).getWidth();
iheight = breakedimages.get(0).getHeight();
context = ipieces;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return duplicate.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return duplicate.get(arg0);
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
ImageView i=new ImageView(context);
i.setLayoutParams(new GridView.LayoutParams(iwidth +5,iheight +5));
i.setPadding(0, 0, 0, 0);
i.setImageBitmap(duplicate.get(arg0));
return i;
}
}
}
can any one do the need for me as i have stuck here how to move the images among themselves