在ScrollView Android Studio中将锚点滚动到底部

时间:2018-11-05 17:45:57

标签: java android scrollview

可以锚定scrollView的底部,  这样一来,当显示一个项目时,它会切掉顶部而不是底部。我在fragments中有5个scrollView,当单击“下一个” button时,它们会有一个动画可以滑入。我希望膨大的fragment底部可见。如您所见,“行3”的底部不在屏幕上。

我尝试以编程方式滚动“下一步”按钮上的scrollView,点击:

scrollView.post(new Runnable() {
                @Override
                public void run() {
                    scrollView.fullScroll(ScrollView.FOCUS_DOWN);
                }
            });

但是,由于延迟了动画过渡,因此无法提供所需的结果。

Screenshot

我的动画:

private void AnimateContainer(@NonNull final ViewGroup container){
    ValueAnimator slideAnimator = ValueAnimator
            .ofInt(container.getHeight(), 140)
            .setDuration(300);


    // we want to manually handle how each tick is handled so add a
    // listener
    slideAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            // get the value the interpolator is at
            Integer value = (Integer) animation.getAnimatedValue();
            // I'm going to set the layout's height 1:1 to the tick
            container.getLayoutParams().height = value.intValue();
            // force all layouts to see which ones are affected by
            // this layouts height change
            container.requestLayout();
        }
    });

    // create a new animationset
    AnimatorSet set = new AnimatorSet();
    // since this is the only animation we are going to run we just use
    // play
    set.play(slideAnimator);
    // this is how you set the parabola which controls acceleration
    set.setInterpolator(new AccelerateDecelerateInterpolator());
    // start the animation
    set.start();

    btn_Back.setVisibility(View.INVISIBLE);
    btn_Next.setVisibility(View.INVISIBLE);

    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            ChangeFrag();
        }
    }, 180L);
}

更改片段方法:

private void ChangeFrag(){
    FragmentTransaction fr = getFragmentManager().beginTransaction();
    fr.setCustomAnimations(R.anim.slide_in_right,R.anim.slide_out_left);
    fr.replace(R.id.containerRow2,new row2()).commit();
    editable = false;

0 个答案:

没有答案