1. Are you ready for the Galaxy S20? Here is everything we know so far!

RecyclerView Scroll Listener

Discussion in 'Android Development' started by umtblbl, Aug 6, 2019.

  1. umtblbl

    umtblbl Newbie
    Thread Starter

    Hi friends I will hide the header contained in the recyclerView according to the scrolling level and make it visible. But I couldn't find a listener I could use for this.
    The setOnScrollChangeListener method always returns 0.0.
    The addOnScrollListener method returns acceleration-sensitive dx and dy values.
    I think I need to process the RecyclerView according to the alignment of the y values. Any suggestions?
     

    Advertisement

  2. wseng92

    wseng92 Android Enthusiast

    Please show us how you added the header contained in the recyclerView.
     
  3. umtblbl

    umtblbl Newbie
    Thread Starter

    Code (Text):
    1.  
    2. public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
    3.  
    4.     LayoutInflater inflater;
    5.     ArrayList<String> list;
    6.  
    7.     private static final int TYPE_HEADER = 0;
    8.     private static final int TYPE_LIST = 1;
    9.  
    10.  
    11.     public RecyclerViewAdapter(Context context) {
    12.         inflater = LayoutInflater.from(context);
    13.         list = new ArrayList<String>();
    14.         list.add("İstanbul");
    15.         list.add("Ankara");
    16.         list.add("Erzincan");
    17.        
    18.     }
    19.  
    20.  
    21.     @Override
    22.     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    23.  
    24.         View view;
    25.  
    26.  
    27.         if (viewType == TYPE_HEADER) {
    28.             view = inflater.inflate(R.layout.header, parent, false);
    29.             return new ViewHolder(view, viewType);
    30.         } else if (viewType == TYPE_LIST) {
    31.             view = inflater.inflate(R.layout.item, parent, false);
    32.             return new ViewHolder(view, viewType);
    33.         } else {
    34.             return null;
    35.         }
    36.  
    37.  
    38.     }
    39.  
    40.     @Override
    41.     public void onBindViewHolder(ViewHolder holder, int position) {
    42.  
    43.         if(holder.view_type == TYPE_LIST) {
    44.  
    45.             holder.txtItem.setText(list.get(--position));
    46.         }
    47.         else if(holder.view_type == TYPE_HEADER) {
    48.  
    49.         }
    50.  
    51.     }
    52.  
    53.     @Override
    54.     public int getItemCount() {
    55.         return list.size() + 1;
    56.     }
    57.  
    58.  
    59.     class ViewHolder extends RecyclerView.ViewHolder {
    60.  
    61.         TextView txtItem;
    62.         int view_type;
    63.  
    64.         public ViewHolder(View itemView, int viewType) {
    65.             super(itemView);
    66.  
    67.             if (viewType == TYPE_LIST) {
    68.                 txtItem = (TextView) itemView.findViewById(R.id.textView);
    69.                 view_type = 1;
    70.             } else if (viewType == TYPE_HEADER) {
    71.                 view_type = 0;
    72.             }
    73.  
    74.  
    75.         }
    76.  
    77.     }
    78.  
    79.  
    80.     @Override
    81.     public int getItemViewType(int position) {
    82.  
    83.         if (position == 0)
    84.             return TYPE_HEADER;
    85.         return TYPE_LIST;
    86.     }
    87. }
    88.  
     
  4. wseng92

    wseng92 Android Enthusiast

    What scrolling level you mean?
     
  5. umtblbl

    umtblbl Newbie
    Thread Starter

    What I want to do; Scrolling in the form of animation with scrollTo (0, header.getHeight ()), if scrolling is left below half of the header size if scrollTo (0,0) is left below half.
     
  6. umtblbl

    umtblbl Newbie
    Thread Starter

    What I want to do; Scrolling in the form of animation with scrollTo (0, header.getHeight ()), if scrolling is left below half of the header size if scrollTo (0,0) is left below half.
     
  7. wseng92

    wseng92 Android Enthusiast

    It's a bit hard for me to understand. Can you show us the screen shot of your UI ?
     
  8. umtblbl

    umtblbl Newbie
    Thread Starter

  9. wseng92

    wseng92 Android Enthusiast

    Still unclear. When you scroll the list to bottom, you don't want the header to be hidden?
     
  10. umtblbl

    umtblbl Newbie
    Thread Starter

    Yes, but in an animated way. And I just want to do it for header
     
Loading...
Similar Threads - RecyclerView Scroll Listener
  1. Hardik Thummar
    Replies:
    0
    Views:
    452
  2. umtblbl
    Replies:
    3
    Views:
    293
  3. umtblbl
    Replies:
    0
    Views:
    481
  4. james04gr
    Replies:
    1
    Views:
    471
  5. Lalox3
    Replies:
    6
    Views:
    505
  6. Jatin Soni
    Replies:
    2
    Views:
    725
  7. Jazelle Ann Capili Capuli
    Replies:
    0
    Views:
    801
  8. Bojan Dolić
    Replies:
    5
    Views:
    732
  9. Marl Atkins
    Replies:
    2
    Views:
    857
  10. Jesse N Lentz
    Replies:
    2
    Views:
    812

Share This Page

Loading...