나는 onTouchListener으로 해결하고
gridview.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
int desplazamiento[]={0,0};
campo.getLocationOnScreen(desplazamiento);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mx = event.getX();
my = event.getY();
return false;
case MotionEvent.ACTION_MOVE:
curX = event.getX();
curY = event.getY();
campo.scrollBy((int) (mx - curX), (int) (my - curY));
mx = curX;
my = curY;
return false;
case MotionEvent.ACTION_UP:
curX = event.getX();
curY = event.getY();
campo.scrollBy((int) (mx - curX), (int) (my - curY));
return false;
}
return false;
}
});
zoom.setOnZoomInClickListener(new OnClickListener() {
public void onClick(View v) {
adaptador.incZoom(fondo, gridview);
gridview.setAdapter(adaptador);
}
});
zoom.setOnZoomOutClickListener(new OnClickListener() {
public void onClick(View v) {
adaptador.decZoom(fondo, gridview);
gridview.setAdapter(adaptador);
}
});
}
연장 BaseAdapter 나는 줌 두 가지 방법 넣어 :
공용 클래스 ImageAdapter는 {
public ImageAdapter(Context context) {
mContext = context;
metrics = mContext.getResources().getDisplayMetrics();
float dp = 80f;
float fpixels = metrics.density * dp;
CUADRO = (int) (metrics.density * dp + 0.5f);
}
public int getCount() {
return 64;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
@SuppressLint("NewApi")
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) { // if it's not recycled, initialize some attributes
imagen = new ImageView(mContext);
imagen.setLayoutParams(new GridView.LayoutParams(CUADRO, CUADRO));
imagen.setScaleType(ImageView.ScaleType.FIT_XY);
imagen.setPadding(0, 0, 0, 0);
} else {
imagen = (ImageView) convertView;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
imagen.setBackground(drawables[position]);
} else {
imagen.setBackgroundDrawable(drawables[position]);
}
imagen.setImageResource(agua[position]);
return imagen;
}
public void incZoom(ImageView fondo, GridView terreno) {
int incremento = CUADRO*10/100;
CUADRO = CUADRO+incremento;
terreno.getLayoutParams().height=8*CUADRO;
terreno.getLayoutParams().width=8*CUADRO;
fondo.getLayoutParams().height=fondo.getHeight()*110/100;
fondo.getLayoutParams().width=fondo.getWidth()*110/100;
}
public void decZoom(ImageView fondo, GridView terreno) {
int incremento = - CUADRO*10/100;
CUADRO = CUADRO+incremento;
terreno.getLayoutParams().height=8*CUADRO;
terreno.getLayoutParams().width=8*CUADRO;
fondo.getLayoutParams().height=fondo.getHeight()*90/100;
fondo.getLayoutParams().width=fondo.getWidth()*90/100;
}
}
BaseAdapter 확장을