[英]Android java How can I have a animation image move left and STAY there?
所以基本上我有這個,當你點擊圖像時,圖像會向右移動,但是當動畫完成后它會回到原來的位置? 我怎樣才能讓它停在動畫結束的地方? 這是我的代碼
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0%" android:toXDelta="70%" android:duration="1000"/>
</set>
這是我的 slide_in_right.xml
public void sideBar()
{
ImageView sidebar = (ImageView)findViewById(R.id.sidebar);
mSlideInRight = AnimationUtils.loadAnimation(this, R.anim.slide_in_right);
sidebar.startAnimation(mSlideInRight);
}
這是它向右滑動的代碼
使用Animation
setFillAfter(true)
方法來保留動畫。
AlphaAnimation alpha = new AlphaAnimation(1, 0);
alpha.setDuration(600);
alpha.setFillAfter(true);
然后
someView.startAnimation(alpha);
在你的情況下,代碼應該是
public void sideBar()
{
ImageView sidebar = (ImageView)findViewById(R.id.sidebar);
mSlideInRight = AnimationUtils.loadAnimation(this, R.anim.slide_in_right);
mSlideInRight.setFillAfter(true);
sidebar.startAnimation(mSlideInRight);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.