Recyclerview Scrolllistener - Animate view visibility

Asked

Viewed 71 times

0

I want a view containing some buttons to disappear and appear when I slide the recycleview as in Coordinator layout:

inserir a descrição da imagem aqui

but currently this way, and he has no animation, just fades and appears: inserir a descrição da imagem aqui

Current code:

rv_noticas.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            y=dy;

            if (dy > 0) {
                Log.i(TAG, "onScrolled: " + "DOWN");
                //layoutbotoes.setVisibility(View.GONE);
                layoutbotoes.setVisibility(View.GONE);

            } else {
                Log.i(TAG, "onScrolled: " + "UP");
                layoutbotoes.setVisibility(View.VISIBLE);


                // Scrolling down
                //layoutbotoes.setVisibility(View.VISIBLE);

            }
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if(RecyclerView.SCROLL_STATE_IDLE ==newState){
                // fragProductLl.setVisibility(View.VISIBLE);
                if(y<=0){
                    layoutbotoes.setVisibility(View.VISIBLE);


                }
                else{
                    y=0;
                    layoutbotoes.setVisibility(View.GONE);
                }
            }
        }


    });
  • Browse animations https://developer.android.com/guide/topics/graphics/prop-animation.html

1 answer

2


Try to put this in the xml layout, top that part

    xmlns:app="http://schemas.android.com/apk/res-auto"

Then in the layout where the buttons meet

app:layout_scrollFlags="scroll|enterAlways"

In case I use this to look like the first image, where the Toolbar hides according to the scroll

  • could you further detail your answer ? I touch something in java ? add only that in xml? because I added and did not change anything

  • Igor in the case what I said would be for the Toolbar. But I think if you follow this example http://blog.grafixartist.com/toolbar-animation-with-android-support-library/ .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.