Hola, estoy usando el widget Galería para mostrar las imágenes descargadas de Internet.Android Gallery acercar/alejar
para mostrar varias imágenes y me gustaría tener un zoom gradual mientras las personas se deslizan hacia arriba y hacia abajo en la pantalla. Sé cómo implementar el evento táctil, lo único que no sé es cómo hacer que la vista de la galería crezca gradualmente. No quiero ampliar una imagen. Quiero que la galería se acerque o aleje gradualmente.
EDIT3: Logré hacer zoom en la parte visible de la galería, pero el problema es que necesito encontrar la manera de que la galería lo descubra y actualice también sus otros hijos.
Lo que pasa es que si 3 imágenes son visibles a continuación, se inicia el zoom y la galería se pone más pequeño, también lo hacen las imágenes, pero lo me gustaría en este caso es más imágenes para ser visible pero no sabe cómo para alcanzar este efecto deseado Aquí está el código completo:
public class Gallery1 extends Activity implements OnTouchListener {
private static final String TAG = "GalleryTest";
private float zoom=0.0f;
// Remember some things for zooming
PointF start = new PointF();
PointF mid = new PointF();
Gallery g;
LinearLayout layout2;
private ImageAdapter ad;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery_1);
layout2=(LinearLayout) findViewById(R.id.layout2);
// Reference the Gallery view
g = (Gallery) findViewById(R.id.gallery);
// Set the adapter to our custom adapter (below)
ad=new ImageAdapter(this);
g.setAdapter(ad);
layout2.setOnTouchListener(this);
}
public void zoomList(boolean increase) {
Log.i(TAG, "startig animation");
AnimatorSet set = new AnimatorSet();
set.playTogether(
ObjectAnimator.ofFloat(g, "scaleX", zoom),
ObjectAnimator.ofFloat(g, "scaleY", zoom)
);
set.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animator animation) {
}
@Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
set.setDuration(100).start();
}
public class ImageAdapter extends BaseAdapter {
private static final int ITEM_WIDTH = 136;
private static final int ITEM_HEIGHT = 88;
private final int mGalleryItemBackground;
private final Context mContext;
private final Integer[] mImageIds = {
R.drawable.gallery_photo_1,
R.drawable.gallery_photo_2,
R.drawable.gallery_photo_3,
R.drawable.gallery_photo_4,
R.drawable.gallery_photo_5,
R.drawable.gallery_photo_6,
R.drawable.gallery_photo_7,
R.drawable.gallery_photo_8
};
private final float mDensity;
public ImageAdapter(Context c) {
mContext = c;
// See res/values/attrs.xml for the <declare-styleable> that defines
// Gallery1.
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 1);
a.recycle();
mDensity = c.getResources().getDisplayMetrics().density;
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
convertView = new ImageView(mContext);
imageView = (ImageView) convertView;
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new Gallery.LayoutParams(
(int) (ITEM_WIDTH * mDensity + 0.5f),
(int) (ITEM_HEIGHT * mDensity + 0.5f)));
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mImageIds[position]);
return imageView;
}
}
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE
&& event.getPointerCount() > 1) {
midPoint(mid, event);
if(mid.y > start.y){
Log.i(TAG, "Going down (Math.abs(mid.y - start.y)= "+(Math.abs(mid.y - start.y))+" and zoom="+zoom); // going down so increase
if ((Math.abs(mid.y - start.y) > 10) && (zoom<2.5f)){
zoom=zoom+0.1f;
midPoint(start, event);
zoomList(true);
}
return true;
}else if(mid.y < start.y){
Log.i(TAG, "Going up (Math.abs(mid.y - start.y)= "+(Math.abs(mid.y - start.y))+" and zoom="+zoom); //smaller
if ((Math.abs(mid.y - start.y) > 10) &&(zoom>0.1)){
midPoint(start, event);
zoom=zoom-0.1f;
zoomList(false);
}
return true;
}
}
else if (event.getAction() == MotionEvent.ACTION_POINTER_DOWN) {
Log.e(TAG, "Pointer went down: " + event.getPointerCount());
return true;
}
else if (event.getAction() == MotionEvent.ACTION_UP) {
Log.i(TAG, "Pointer going up");
return true;
}
else if (event.getAction() == MotionEvent.ACTION_DOWN) {
Log.i(TAG, "Pointer going down");
start.set(event.getX(), event.getY());
return true;
}
return false;
// indicate event was handled or not
}
private void midPoint(PointF point, MotionEvent event) {
float x = event.getX(0) + event.getX(1);
float y = event.getY(0) + event.getY(1);
point.set(x/2, y/2);
}
que darse cuenta probablemente voy a tener que ampliar la Galería o incluso otro Ver grupo o crear mi propia clase, pero no sé por dónde empezar: el método que utiliza el responsable de la ampliación ...
EDIT4: No sé si la pregunta es lo suficientemente clara. Aquí está un ejemplo de estados:
un Estado: estado inicial, tenemos 3 imágenes en la vista
Estado 2: detectamos toques verticales que suben con 2 dedos = tenemos que alejar estado
3: comenzamos a hacer zoom = animación en la galería o en los niños ???
estado 4: Galería detecta que se trata de 3 niños son más pequeños
estado 5: galería añade 1/Los niños más de acuerdo con el nuevo espacio disponible
ULTIMA ACTUALIZACION: Gracias a todos los que se han publicado, pero me finalmente haber llegado a una conclusión y que consiste en no utilizar Galería en absoluto: 1. está obsoleto 2. no es lo suficientemente adaptable para mi caso
Si desea animar varias imágenes a la vez es posible que desee considerar el uso de OpenGL , Estoy usando biblioteca libgdx: https://github.com/libgdx/libgdx
gracias Akos por su respuesta. Lo he intentado, pero como utilizo animaciones en la galería, el resultado es el mismo que antes: lo visible son enlaces, pero no se dibujan nuevas vistas.Si aplico la animación a una sola vista, esa solo se acerca. Si utilizo scaleX/scaleY lo mismo ... He decidido crear mi propia Surfaceview y simplemente dibujar los mapas de bits – vallllll
Hola, ¿Pueden pasar aquí el código completo, por favor? – Hasmukh
Por favor, ponga su código completo aquí ... lo necesito con urgencia ... ¡Gracias de antemano! –