Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regarding ProperScrolling in Horizontal Recycler View

I have issues scrolling in horizontal recycler view.For eg if i have 10 items,very first time,I am able to scroll till last item,But if i go to first item and then scroll again to last item,it is not moving to last item.

Is this issue related to scrolling,Should i override for scrolling,if that's case.

This is my fragment class declaration

      LinearLayoutManager layoutManager
            = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
    mRecyclerView = (RecyclerView)v. findViewById(R.id.recycler_view);
    adapter  = new MyRecyclerAdapter(getActivity());
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setAdapter(adapter);

and in my adapter

public class MyRecyclerAdapter extends RecyclerView.Adapter<MyRecyclerAdapter.CustomViewHolder> {

private Context mContext;
JobSiteActivity mjobSiteActivity;
ImageLoader loader = null;

public MyRecyclerAdapter(Activity activity) {
    this.mContext = activity;
    mjobSiteActivity = (JobSiteActivity)activity;
    loader = mjobSiteActivity.getImageLoader();
}

@Override
public CustomViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.image_detail_fragment, null);

    CustomViewHolder viewHolder = new CustomViewHolder(view);
    return viewHolder;
}

@Override
public void onBindViewHolder(CustomViewHolder customViewHolder, int i) {
    //FeedItem feedItem = feedItemList.get(i);

    //Download image using picasso library
  /*  Picasso.with(mContext).load(feedItem.getThumbnail())
            .error(R.drawable.placeholder)
            .placeholder(R.drawable.placeholder)
            .into(customViewHolder.imageView);*/

    customViewHolder.imageView.setImageUrl(Images.imageThumbUrls[i], loader);
    customViewHolder.imageView.setOnClickListener(clickListener);
    customViewHolder.imageView.setTag(customViewHolder);


    //Setting text view title

}

@Override
public int getItemCount() {
    //return (null != feedItemList ? feedItemList.size() : 0);
    return  Images.imageThumbUrls.length;
}

public class CustomViewHolder extends RecyclerView.ViewHolder {
    protected NetworkImageView imageView;


    public CustomViewHolder(View view) {
        super(view);
        this.imageView = (NetworkImageView) view.findViewById(R.id.imageView);

    }
}


View.OnClickListener clickListener = new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        CustomViewHolder holder = (CustomViewHolder) view.getTag();
        int position = holder.getLayoutPosition();
        int position1 = holder.getAdapterPosition();
        Toast.makeText(mContext, "layoutPs"+position+"adapPos"+position, Toast.LENGTH_SHORT).show();
    }
};

}

I am trying to use horizontal Grid view which comes with V17 leanback which also extends recycleView,but Still I am also facing similar sort of issue,

If i try to add any item to recycler view at runtime for eg on taking Photo,it is also not getting added,It allocates space and it is empty?Very hard to understand or debug on this issue.

like image 307
Rakesh Avatar asked Dec 17 '15 11:12

Rakesh


People also ask

How to add and update recyclerview items when horizontal scroll it?

This example will show you how to add and update RecyclerView items when horizontal scroll it. When the user scrolls from left to right at the beginning of RecyclerView, it will add a new item at the beginning. When the user scrolls from right to left at the end of RecyclerView, it will insert another new item at the ending.

How to add new items in recyclerview?

When user scroll from left to right at the beginning of RecyclerView, it will add a new item at beginning. When user scroll from right to left at the end of RecyclerView, it will insert another new item at the ending.

What is dynamic horizontal recyclerview in Android using Firebase FireStore?

How to Create Dynamic Horizontal RecyclerView in Android using Firebase Firestore? HorizontalRecyclerView is seen in many apps. It is generally used to display the categories in most apps and websites. This type of RecyclerView is seen in many E-commerce apps to indicate categories in the app.

How many recyclerviews does a fragment layout have?

I have a fragment layout that is a part of a PageViewer. The fragment has 2 RecyclerViews - one on the top of the layout which is horizontal, the other one at the bottom which is vertical.


1 Answers

Try to use layoutManager like this, may help you

LinearLayoutManager layoutManager=new LinearLayoutManager(getApplicationContext(),LinearLayoutManager.HORIZONTAL,false);
like image 162
ajantha Avatar answered Oct 26 '22 18:10

ajantha