so I have the next problem with my app.I am using TranslateAnimation for my layout and after it ends I set for my layout new l,t,b,r, in order to replace it phisically,also.Here is the code:
package com.Borislav_Nazarski_SM;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
public class main extends Activity implements OnClickListener,AnimationListener {
RelativeLayout L;
ImageView imageView4;
Animation inFromLeftAnimation,inFromRightAnimation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
L = (RelativeLayout)this.findViewById(R.id.mainlayout);
imageView4 = (ImageView)this.findViewById(R.id.imageView4);
imageView4.setOnClickListener(this);
//animation that move the layout from top to 202px
inFromLeftAnimation = new TranslateAnimation(0,0,0,202);
inFromLeftAnimation.setDuration(12500);
inFromLeftAnimation.setInterpolator(new AccelerateInterpolator());
inFromLeftAnimation.setFillEnabled(true);
inFromLeftAnimation.setFillAfter(true);
inFromLeftAnimation.setFillBefore(false);
inFromLeftAnimation.setAnimationListener(this);
//animation that move the layout back
inFromRightAnimation = new TranslateAnimation(0,0,202,0);
inFromRightAnimation.setDuration(12500);
inFromRightAnimation.setInterpolator(new AccelerateInterpolator());
inFromRightAnimation.setFillEnabled(true);
inFromRightAnimation.setFillBefore(false);
inFromRightAnimation.setFillAfter(true);
inFromRightAnimation.setAnimationListener(this);
}
public void onClick(View v) {
if(v==imageView4)
{
if(v.isSelected())
{
v.setSelected(false);
L.clearAnimation();
L.startAnimation(inFromRightAnimation);
}
else
{
v.setSelected(true);
L.clearAnimation();
L.startAnimation(inFromLeftAnimation);
}
}
}
public void onAnimationEnd(Animation animation) {
if(animation==inFromLeftAnimation){
L.layout(0,0,800,606);
}
if(animation==inFromRightAnimation){
L.layout(0,-202,800,404);
}
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
Here is the layout xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#00FF00" android:orientation="horizontal" android:id="@+id/mainlayout" android:layout_height="606px" android:layout_gravity="bottom">
<ImageView android:src="@drawable/icon" android:id="@+id/imageView1" android:layout_width="130px" android:layout_height="180px" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"></ImageView>
<ImageView android:src="@drawable/icon" android:id="@+id/imageView2" android:layout_width="130px" android:layout_height="180px" android:layout_below="@+id/imageView3"></ImageView>
<ImageView android:src="@drawable/icon" android:id="@+id/imageView3" android:layout_centerVertical="true" android:layout_width="130px" android:layout_height="180px" android:layout_below="@+id/imageView1"></ImageView>
<ImageView android:src="@drawable/icon" android:id="@+id/imageView4" android:clickable="true" android:layout_width="130px" android:layout_height="180px" android:layout_toRightOf="@+id/imageView3" android:layout_below="@+id/imageButton1"></ImageView>
<ImageButton android:id="@+id/imageButton1" android:src="@drawable/icon" android:layout_width="130px" android:layout_height="180px" android:layout_toRightOf="@+id/imageView1" android:layout_above="@+id/imageView3"></ImageButton>
<ImageButton android:id="@+id/imageButton2" android:src="@drawable/icon" android:layout_width="130px" android:layout_height="180px" android:layout_toRightOf="@+id/imageView2" android:layout_below="@+id/imageView4"></ImageButton>
</RelativeLayout>
So the problem is that after the animation reach it's end -there is a "jump" down or up depending on the animation - may be something with the positioning I am using L.layout(... does not work.Please,help.Thanks in advance
This is a known bug with animationListeners. As a workaround you have to subclass your View and override onAnimationEnd there instead. See also android animation is not finished in onAnimationEnd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With