我有一個相對佈局(姑且稱之爲A),滾動視圖內,相對佈局內(我們稱這種佈局B)動畫視圖對齊父頂部
我試圖要做的是從A中移除一個孩子,將其插入B並將其與父頂部(在操作欄下方)對齊。
我一直在試圖製作這張幻燈片的動畫,然後回到原來的位置,沒有任何運氣。
任何想法如何執行此動畫?
我有一個相對佈局(姑且稱之爲A),滾動視圖內,相對佈局內(我們稱這種佈局B)動畫視圖對齊父頂部
我試圖要做的是從A中移除一個孩子,將其插入B並將其與父頂部(在操作欄下方)對齊。
我一直在試圖製作這張幻燈片的動畫,然後回到原來的位置,沒有任何運氣。
任何想法如何執行此動畫?
既然你是動畫布局的更改
嘗試添加以下內容到佈局塊:
android:animateLayoutChanges="true"
來源:http://developer.android.com/guide/topics/graphics/prop-animation.html#layout
非常晚的答覆,但這裏是我如何管理這樣的:
center_to_top_center.xml(位於res/anim /)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fillAfter="true"
android:fromXDelta="0%p"
android:fromYDelta="00%p"
android:toXDelta="00%p"
android:toYDelta="-40%p" />
</set>
HomeActivity.java
public class HomeActivity extends FragmentActivity {
@InjectView(R.id.imageView2)
ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_home, false);
beginLogoAnimation();
}
private void beginLogoAnimation(){
Animation translateAnim= AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.center_to_top_center);
translateAnim.setFillAfter(true);
translateAnim.setFillEnabled(true);
translateAnim.setFillBefore(false);
translateAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
mImageView.startAnimation(translateAnim);
}
}
activity_home.xml
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:layout_centerInParent="true"
android:layout_marginTop="15dp"
android:layout_centerHorizontal="true"
android:src="@drawable/logo"
/>