0

My app has a tabbed screen with three fragments, two of which are the same but with different data.

Initial screen

With comments

Clicking the comment down the bottom brings up the full list of comments and clicking the [x] closes the comments. This is done through animations and .setVisibility().

The problem is I can only do this once as clicking the comment after closing it does nothing.

Bringing up the comments is shown here - from debugging, the onClick fires if I don't mess with the visibilities so they must be causing a problem somewhere

comment_overview.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
            handleCommentOverviewClick(v);
       }
});
...

private void handleCommentOverviewClick(View v) {
        Log.d("OPEN", "open");
        scrollView.fullScroll(ScrollView.FOCUS_UP);
        Animation bottomUp = AnimationUtils.loadAnimation(getContext(),
                R.anim.slide_in_bottom);
        bottomUp.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                bottom_info_section.setVisibility(View.GONE);
                // animation.cancel();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });

        comment_section.startAnimation(bottomUp);
        comment_section.setVisibility(View.VISIBLE);
}

Closing the comments is similar and shown below

private void handleCommentsClose(View v) {
        Log.d("CLOSE", "cls");
        Animation topDown = AnimationUtils.loadAnimation(getContext(),
                R.anim.slide_out_bottom);
        topDown.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {}

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

            @Override
            public void onAnimationRepeat(Animation animation) {}
        });
        comment_section.startAnimation(topDown);
        bottom_info_section.setVisibility(View.VISIBLE);
    }

I've tried following advice of making the fragment implement OnClickListener and handling each clickable in a switch but I got the same behaviour - it would work once but not again unless I navigated away and came back.

Would love any suggestions as I'm kinda stuck

2 Answers2

0

Maybe local variable bottomUp, topDown will be deleted when handleComment ends. Then onAnimationEnd won't called back and the view isn't gone. Atempt to declare it outside.

Animation topDown;

topDown = AnimationUtils.loadAnimation(getContext(),
                R.anim.slide_out_bottom);
cnux9
  • 46
  • 3
  • Maybe. I did have it declared in onCreateView but made it its own function when I was trying a few other things. Will try it anyway – MySupersuit Mar 27 '21 at 23:34
0

Pretty sure the way I was animating it was messing it up. Switching to the Transition animations used here helped.

private void handleCommentOverviewClick(ViewGroup v) {
        Log.d("OPEN", "open");
        scrollView.fullScroll(ScrollView.FOCUS_UP);

        Transition transition = new Slide(Gravity.BOTTOM);
        transition.setDuration(200);
        transition.addTarget(comment_section);

        TransitionManager.beginDelayedTransition(v, transition);
        comment_section.setVisibility(View.VISIBLE);

    }