Horizontal RecyclerView with nice animation Android

一笑奈何 提交于 2019-12-13 07:59:14

问题


How to make such like horizontal recycle view with nice UI animation. Note: I can make horizontal recyclerview. but how can it start from middle and when scroll it comes in start? and secondly background image will be visible or invisible animatedly according scrolling.

I want to make such like I already try ItemDecoration but when it load fast time start from left after if start from center any help.


回答1:


Set padding left on Recyclerview as below code to start your recyclerView row as per padding left :

your Xml code should be like this :

<LinearLayout
           android:layout_marginTop="8dp"
           android:background="@drawable/banner2"
           android:layout_width="match_parent"
           android:layout_height="240dp">



           <android.support.v7.widget.RecyclerView
               android:paddingLeft="180dp"
               android:layout_marginTop="17dp"
               android:id="@+id/recycler_kids"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:clipToPadding="false"
               app:layout_behavior="@string/appbar_scrolling_view_behavior" />


       </LinearLayout>

Look into this for detect hiding row on recyclerview to show background image Hiding views in RecyclerView




回答2:


To Start horizontal RecyclerView with a starting empty space Use:

recyclerView.addItemDecoration(new HorizontalSpaceItemDecoration(700));

and define Class: HorizontalSpaceItemDecoration(); as

public class HorizontalSpaceItemDecoration extends RecyclerView.ItemDecoration {

    private final int mHorizontalSpaceWidth;

    public HorizontalSpaceItemDecoration(int mHorizontalSpaceWidth) {
        this.mHorizontalSpaceWidth = mHorizontalSpaceWidth;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                               RecyclerView.State state) {
        if (parent.getChildAdapterPosition(view) == 0) {
            outRect.left = mHorizontalSpaceWidth;
        }
    }



回答3:


my solution is to add blank item at first.

    @Override
    public int getItemViewType(int position) {
        if (position==0){
            return 1;
        }else {
            return super.getItemViewType(position);
        }
    }

you need to create blank item in xml for that



来源:https://stackoverflow.com/questions/48745980/horizontal-recyclerview-with-nice-animation-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!