如何在动画停止后定位ScrollView

时间:2012-06-06 16:31:49

标签: android android-widget android-animation

我有一个包含LinearLayout的ScrollView,在LinearLayout中我有一个视图,我根据被按下的按钮展开或折叠。这件作品很好用。

我想要做的是重新定位ScrollView,以便在展开视图时自动重新定位滚动视图,以便可以看到展开的视图。我希望视图能够自动重新定位,这样用户就不必滚动了 目前,当视图扩展时,所有内容都会被推下,您必须向上滚动才能查看新扩展的内容。我在动画结束后尝试重新定位,但该部分代码永远不会触发。以下是我的代码。

public void animateExpandCollapse(View v) {

        View captionLayout = null;
        View parentLayout  = null;

        if(v.getId() == R.id.squareCal) {
            captionLayout = (LinearLayout) findViewById(R.id.layout3);
            parentLayout  = (LinearLayout) findViewById(R.id.squareLayout);
        } else if(v.getId() == R.id.circleCal) {
            captionLayout = (LinearLayout) findViewById(R.id.layout2);
            parentLayout  = (LinearLayout) findViewById(R.id.circleLayout01);
        }


        if (!more) {
            dda = new DropDownAnim(captionLayout, 350, false);
            more=true;
        } else {
            dda = new DropDownAnim(captionLayout, 350, true);
            more=false;
        }
        dda.setDuration(350);
        parentLayout.startAnimation(dda);

        // Here, I want to position ScrollView to the bottom
        // After the animation has finished but this never fires.
        if(dda.hasEnded() ) {
            ScrollView sv = (ScrollView)findViewById(R.id.calScroller);
            sv.scrollTo(0, sv.getBottom());
        }

        return;
    }

1 个答案:

答案 0 :(得分:0)

在线搜索后,我找到了以下解决方案。我希望这有助于某人。

dda.setAnimationListener(new AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }
            @Override
            public void onAnimationRepeat(Animation animation) {
            }
            @Override
            public void onAnimationEnd(Animation animation) {
                ScrollView sv = (ScrollView)findViewById(R.id.calScroller);
                sv.scrollTo(0, sv.getBottom());
            }
        });
相关问题