heres the code iused to make grid view..how to add click vents on images so dat image can be flip.pllzzzzzz helpppp
public class GameScreen extends View {
private static final String TAG = "Touchimage";
private Game game;
public GameScreen(Context context) {
super(context);
this.game = (Game) context;
setFocusable(true);
setFocusableInTouchMode(true);
}
public GameScreen(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public GameScreen(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
private float width; // width of one tile
private float height; // height of one tile
private int selX; // X index of selection
private int selY; // Y index of selection
private final Rect selRect = new Rect();
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
width = w / 4f;
height = h / 4f;
getRect(selX, selY, selRect);
Log.d(TAG, "onSizeChanged: width " + width + ", height "
+ height);
super.onSizeChanged(w, h, oldw, oldh);
}
private void getRect(int x, int y, Rect rect) {
rect.set((int) (x * width), (int) (y * height), (int) (x
* width + width), (int) (y * height + height));
}
@Override
protected void onDraw(Canvas canvas) {
Paint background = new Paint();
background.setColor(getResources().getColor(
R.color.puzzle_background));
canvas.drawRect(0, 0, getWidth(), getHeight(), background);
Paint dark = new Paint();
dark.setColor(getResources().getColor(R.color.puzzle_dark));
for (int i = 0; i<4; i++) {
canvas.drawLine(0, i * height, getWidth(), i * height,
dark);
canvas.drawLine(0, i * height + 1, getWidth(), i * height
+ 1, dark);
canvas.drawLine(i * width, 0, i * width, getHeight(), dark);
canvas.drawLine(i * width + 1, 0, i * width + 1,
getHeight(), dark);
}
Paint foreground = new Paint(Paint.ANTI_ALIAS_FLAG);
FontMetrics fm = foreground.getFontMetrics();
// Centering in X: use alignment (and X at midpoint)
float x = width / 2;
// Centering in Y: measure ascent/descent first
float y = height / 2- (fm.ascent + fm.descent) / 2;
Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
//ImageView img= new ImageView(Tutorial2D.this);
//img.setImageBitmap(_scratch);
//canvas.drawColor(Color.BLACK);
for (int i = 0; i<4; i++) {
for (int j = 0; j<4; j++) {
canvas.drawBitmap(_scratch, i
* width+x/2 , j * height+y/2 , foreground);
}
}
//canvas.drawBitmap(_scratch, 0, 0, null);
super.onDraw(canvas);
}
}