簡體   English   中英

以相對布局對視圖進行動畫處理以對齊父頂部

[英]Animate view in relative layout to align parent top

我有一個相對的布局(我們稱它為A),在滾動視圖中,一個相對的布局(我們稱其為B)。

我想做的是從A中刪除一個孩子,將其插入B並將其與父頂部對齊(在操作欄的正下方)。

我一直在嘗試為這張幻燈片制作動畫,然后又回到原來的位置,沒有任何運氣。

知道如何執行此動畫嗎?

回復很晚,但這是我的處理方式:

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"
    />

由於您是對布局進行動畫處理
嘗試將其添加到布局塊中:

android:animateLayoutChanges="true"

來源: http : //developer.android.com/guide/topics/graphics/prop-animation.html#layout

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM