动画结束后滚动,android

时间:2011-06-20 09:34:38

标签: java android layout animation

我有一系列的观点,电影中的座位。我需要对它们应用一组动画(缩放和平移)来进行某种缩放。我将动画应用到每个视图。动画看起来像这样:

    AnimationSet set = new AnimationSet(context, null);

    float toXDelta = (place.getX() * 2) - place.getX();
    float toYDelta = (place.getY() * 2) - place.getY();
    Animation translate = new TranslateAnimation(0, toXDelta, 0, toYDelta);
    translate.setDuration(4000);
    translate.setFillAfter(true);
    translate.setFillEnabled(true);

    Animation scale = new ScaleAnimation(1, 5, 1, 5);
    scale.setDuration(4000);
    scale.setFillAfter(true);
    scale.setFillEnabled(true);

    set.addAnimation(translate);
    set.addAnimation(scale);

    set.setFillAfter(true);
    set.setAnimationListener(new KaroAnimationListener(this));

    animation = set;

所以,我的布局看起来像这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_height="fill_parent"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:padding="10px">
<ScrollView android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_weight="0"
            android:id="@+id/vertical_scroll"
            android:fillViewport="true">
    <HorizontalScrollView
            android:layout_height="fill_parent"
            android:fillViewport="true"
            android:id="@+id/scroll_view"
            android:layout_width="wrap_content">
        <RelativeLayout android:id="@+id/scrollable_places"
                        android:layout_height="wrap_content"
                        android:layout_width="wrap_content">

        </RelativeLayout>
    </HorizontalScrollView>
</ScrollView>

<Button android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:id="@+id/reserve_places_button"
        android:onClick="onReserveClick"
        android:layout_below="@id/vertical_scroll"
        android:layout_weight="1"
        android:text="Bron!"/>

我将观点放入RelativeLayout,标识为scrollable_places。因此,在动画结束后,一些视图超出了屏幕的范围,但没有可用的滚动。 我想我需要重新定义dimentions RelativeLayout or other, parent, layouts,但我不知道如何手动完成。 谢谢!

1 个答案:

答案 0 :(得分:3)

您可以尝试将滚动延迟滚动到ScrollView的这一端,如下所示:

scrollView.postDelayed( new Runnable() {
                @Override
                public void run() {
                    scrollView.fullScroll( View.FOCUS_DOWN);
                }
            }, 4300);

因此,它适合在动画结束后开始,或者您可以在使用AnimationListener收听动画结束后执行此操作,在这种情况下,您可以使用小于4300毫秒的延迟, 300左右的东西会做。

此致  斯特凡

相关问题