Every time you use animation you should set animation start time. Any way you prefer, from simple animation.startNow()
to more complex animation.setStartTime(time); animation.start()
.
Android built-in animation not proper
質問
I am trying to animate an ImageView with a background image. The animation loads fine during the first time but after that becomes laggy and no animation appears.
file ---- main.xml
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
/>
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/editText1"
android:layout_marginRight="30dp"
android:layout_marginTop="52dp"
android:text="Click me" />
file ---- TutorialActivity.java
private isClicked = 0;
private Animation animUp;
private Animation animDown;
animUp = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
animDown = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
animUp.setDuration(500);
animDown.setDuration(500);
Button clickButton = (Button) findViewById(R.id.button2);
clickButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v)
{
if(isClicked == 0)
{
menu.setVisibility(View.VISIBLE);
menu.setAnimation(animUp);
isClicked = 1;
}
else
{
menu.setAnimation(animDown);
menu.setVisibility(View.GONE);
isClicked = 0;
}
}
解決
所属していません StackOverflow