Top Item Alpha Processing in Recyclerview (or ListView) on Android

Asked 2 years ago, Updated 2 years ago, 118 views

I want to make the items at the top disappear naturally in Recyclerview (or ListView) on Android. (The background will show)

I think we can do Alpha processing of the item on the top... I can't think of an idea because it's a structure where items disappear, not a structure where they are covered. In addition, as it scrolls, I think the Alpha processing of the item should continue to be updated.

Is there anyone who can help me with this problem? ^

^

android recyclerview listview alpha

2022-09-22 08:15

2 Answers

When you want to change something according to the scroll of RecyclerView https://github.com/ksoichiro/Android-ObservableScrollView Try this library. You'll be able to realize it very easily For example, if you want to scroll to a certain height and gradually make the toolbar opaque. With the following feeling of peeling~

recyclerView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
            @Override
            public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
                int headerHeight = (int) (DisplayUtils.getDisplaySize(ArticleActivity.this).x / 1.5f) - toolbar.getHeight();
                float ratio = 0;
                if (scrollY > 0 && headerHeight > 0) {
                    ratio = (float) Math.min(Math.max(scrollY, 0), headerHeight) / headerHeight;
                }
                int newAlpha = (int) (ratio * 255);
                toolbarDrawable.mutate().setAlpha(newAlpha);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    toolbar.setBackground(toolbarDrawable);
                } } else {
                    toolbar.setBackgroundDrawable(toolbarDrawable);
                }
            }

            @Override
            public void onDownMotionEvent() {

            }

            @Override
            public void onUpOrCancelMotionEvent(ScrollState scrollState) {

            }
        });


2022-09-22 08:15

Are you saying that you want to make the item at the top disappear whenever you scroll up the list view? (I don't know if I understood correctly.;) Whenever I scroll up the list view, I think I would implement it as below to make it disappear by feeding alpha to the item at the top.

;);)

If you want to disappear little by little like the image below, you can put a view on the top of the Recyclerview and put an image view with alpha from the bottom to the top with the same color as the list view item.

I hope I can be of any help.;

;;


2022-09-22 08:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.