gpt4 book ai didi

android - 在 "end of translate animation"和布局重新定位之间,有一个意外的 "jump"。如何避免?

转载 作者:太空狗 更新时间:2023-10-29 12:55:53 25 4
gpt4 key购买 nike

所以我的应用程序遇到了下一个问题。我正在为我的布局使用 TranslateAnimation,在它结束后我为我的布局设置了新的 l、t、b、r,以便在物理上替换它。这是代码:

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

}
}

这是布局 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>

所以问题是在动画到达结束后 - 根据动画有向下或向上的“跳跃” - 可能与我使用的定位有关 L.layout(... 不起作用。请,帮助。提前致谢

最佳答案

这是 animationListeners 的一个已知错误。作为一种解决方法,您必须将 View 子类化并在那里覆盖 onAnimationEnd 。另见 android animation is not finished in onAnimationEnd

关于android - 在 "end of translate animation"和布局重新定位之间,有一个意外的 "jump"。如何避免?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6884975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com