Bạn có thể làm điều đó với ScaleAnimations
đặt trên ViewFlipper
. Tôi làm một điều tương tự mà không có quy mô thứ hai. Tôi có hai hình ảnh động, một cho xem ra đi và một cho xem sắp tới in Tôi sẽ gửi chúng ở đây như là một điểm khởi đầu cho bạn.
shrink_to_middle.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/linear_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:fillAfter="false"
android:duration="200" />
<translate
android:fromYDelta="0"
android:toYDelta="50%"
android:duration="200"/>
</set>
grow_from_middle.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/linear_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:fillAfter="false"
android:startOffset="200"
android:duration="200" />
<translate
android:fromYDelta="50%"
android:toYDelta="0"
android:startOffset="200"
android:duration="200"/>
</set>
Sau đó, trong ứng dụng tôi đặt chúng vào các ViewFlipper
như thế này:
mViewFlipper.setInAnimation(context, R.anim.grow_from_middle);
mViewFlipper.setOutAnimation(context, R.anim.shrink_to_middle);
Như tôi đã nói, đây không phải chính xác những gì bạn mô tả, nhưng nó khá gần và sẽ giúp bạn bắt đầu.
--EDIT--
Đây là mã bằng cách sử dụng pivotX và pivotY (tốt, chỉ pivotY trong trường hợp của tôi):
shrink_to_middle.xml
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotY="50%"
android:fillAfter="false"
android:duration="200" />
grow_from_middle.xml
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotY="50%"
android:fillAfter="false"
android:startOffset="200"
android:duration="200" />
Cảm ơn các con trỏ. Chắc chắn là một khởi đầu tốt. Thay vì sử dụng một hoạt ảnh khác - dịch, tôi đã tạo pivotX = 50%, pivotY = 50% và một số thay đổi khác. Cảm ơn bạn đã khởi động –
Rất tốt! Cảm ơn bạn đã tip về pivotX, pivotY! – CaseyB
bạn vui lòng cung cấp mã bằng pivotX, pivotY – gypsicoder