• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

RecyclerView Scroll Listener

umtblbl

Member
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?
 
Please show us how you added the header contained in the recyclerView.

Code:
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {

    LayoutInflater inflater;
    ArrayList<String> list;

    private static final int TYPE_HEADER = 0;
    private static final int TYPE_LIST = 1;


    public RecyclerViewAdapter(Context context) {
        inflater = LayoutInflater.from(context);
        list = new ArrayList<String>();
        list.add("İstanbul");
        list.add("Ankara");
        list.add("Erzincan");
        
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view;


        if (viewType == TYPE_HEADER) {
            view = inflater.inflate(R.layout.header, parent, false);
            return new ViewHolder(view, viewType);
        } else if (viewType == TYPE_LIST) {
            view = inflater.inflate(R.layout.item, parent, false);
            return new ViewHolder(view, viewType);
        } else {
            return null;
        }


    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        if(holder.view_type == TYPE_LIST) {

            holder.txtItem.setText(list.get(--position));
        }
        else if(holder.view_type == TYPE_HEADER) {

        }

    }

    @Override
    public int getItemCount() {
        return list.size() + 1;
    }


    class ViewHolder extends RecyclerView.ViewHolder {

        TextView txtItem;
        int view_type;

        public ViewHolder(View itemView, int viewType) {
            super(itemView);

            if (viewType == TYPE_LIST) {
                txtItem = (TextView) itemView.findViewById(R.id.textView);
                view_type = 1;
            } else if (viewType == TYPE_HEADER) {
                view_type = 0;
            }


        }

    }


    @Override
    public int getItemViewType(int position) {

        if (position == 0)
            return TYPE_HEADER;
        return TYPE_LIST;
    }
}
 
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.
 
Still unclear. When you scroll the list to bottom, you don't want the header to be hidden?
 
Back
Top Bottom