android view平移動畫

translateout
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"

           android:fillAfter="true"
           android:duration="500"
           android:fromXDelta="0%"
           android:toXDelta="100%">

</translate>
translatein
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"

           android:fillAfter="true"
           android:duration="500"
           android:fromXDelta="100%"
           android:toXDelta="0">

</translate>

在使用的地方調用

private void showDateControl() {
    if (isShowDateControl) {
        isShowDateControl = false;
        horizontalLv.clearAnimation();
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.translateout);
        horizontalLv.startAnimation(animation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                horizontalLv.setVisibility(View.GONE);
                horizontalLv.clearAnimation();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    } else {
        isShowDateControl = true;
        horizontalLv.setVisibility(View.VISIBLE);
        horizontalLv.clearAnimation();
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.translatein);
        horizontalLv.startAnimation(animation);
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章