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 Member
    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?
     



    1. Download the Forums for Android™ app!


      Download

       
  2. wseng92

    wseng92 Android Enthusiast

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

    umtblbl Member
    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 Member
    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 Member
    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 Member
    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 Member
    Thread Starter

    Yes, but in an animated way. And I just want to do it for header
     
Loading...
Similar Threads - RecyclerView Scroll Listener
  1. shubham1835
    Replies:
    1
    Views:
    278
  2. Dnlaua
    Replies:
    0
    Views:
    573
  3. Nitrogen247
    Replies:
    0
    Views:
    655
  4. GotParty
    Replies:
    4
    Views:
    1,465
  5. Artem Polovin
    Replies:
    0
    Views:
    1,094
  6. Artem Polovin
    Replies:
    0
    Views:
    502
  7. Hardik Thummar
    Replies:
    0
    Views:
    903
  8. umtblbl
    Replies:
    3
    Views:
    491
  9. umtblbl
    Replies:
    0
    Views:
    810
  10. james04gr
    Replies:
    1
    Views:
    724

Share This Page

Loading...