2011-06-21 9 views
21

Actualmente tengo una ImageView a la que estoy aplicando una animación de escala. Esta vista se encuentra dentro de un diseño relativo que tiene layout_height y layout_width establecidos como wrap_content. El problema es que cuando comienza la animación, la vista de la imagen es más grande que su diseño principal y la imagen se corta. ¿Hay alguna manera alrededor de esto?Android: la animación se ve recortada por la vista principal

Este es un ejemplo de trabajo:

archivo xml -

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dip" 
    android:layout_gravity="center_horizontal"> 
    <ImageView 
     android:id="@+id/imgO" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/circle"/> 
    </RelativeLayout> 
</LinearLayout> 

archivo Java -

ImageView imgO; 

ScaleAnimation makeSmaller; 
ScaleAnimation makeBigger; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.titlescreen); 

    //Animation 
    imgO = (ImageView)findViewById(R.id.imgO); 

    makeSmaller = new ScaleAnimation((float)10.0, (float)1.0, (float)10.0, (float)1.0, Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5); 
    makeSmaller.setAnimationListener(new MyAnimationListener()); 
    makeSmaller.setFillAfter(true); 
    makeSmaller.setDuration(500); 
    makeBigger = new ScaleAnimation((float)1.0, (float)10.0, (float)1.0, (float)10.0, Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5); 
    makeBigger.setAnimationListener(new MyAnimationListener()); 
    makeBigger.setFillAfter(true); 
    makeBigger.setDuration(750); 
    imgO.startAnimation(makeBigger); 
} 

class MyAnimationListener implements AnimationListener { 

    public void onAnimationEnd(Animation animation) { 

     ScaleAnimation sa = (ScaleAnimation)animation; 

     if (sa.equals(makeSmaller)) 
      imgO.startAnimation(makeBigger); 
     else 
      imgO.startAnimation(makeSmaller); 
    } 

    public void onAnimationRepeat(Animation animation) { 
    } 

    public void onAnimationStart(Animation animation) { 
    } 

} 

Gracias.

Respuesta

0

Lo arreglé haciendo que todo se llenara y luego centrara las imágenes horizontal y verticalmente.

65

Un poco tarde para usted, pero para todos los que buscan una respuesta: Puede llamar al setClipChildren(false) en los Grupos de Vista adjuntos (como RelativeLayout o LinearLayout).

+10

excelente awser! también puedes limpiar tu código si usas XML: android: clipChildren = "false" – Ricky

+0

Gracias, si esos niños fueran botones, ¿cómo mantendría los eventos onClickListener? Los míos están desapareciendo. – tricknology

+0

¡Excelente respuesta! ¡Gracias! Vale la pena mencionar que es suficiente para establecer clipChildren en "falso" en el padre principal (diseño raíz). – daxgirl

Cuestiones relacionadas