水平的Recycler视图与左,右箭头指示器 [英] Horizontal Recycler view with left and right arrow Indicators

查看:114
本文介绍了水平的Recycler视图与左,右箭头指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用左右箭头指示器实现水平循环视图。因此,如果单击右箭头,则会出现下一个项目,如果单击左箭头,则应显示上一个项目,并且在列表的末尾,左箭头应该消失。我不知道如何实现这一点。有人可以帮我吗?下面是我的Horizo​​ntal Recyclerview适配器。

I am trying to implement a horizontal recycleview with right and left arrow indicators. So what happens is if one clicks the right arrow next item should appear and if one clicks the left arrow the previous item should appear and also at the end of the list the left arrow should disappear. I have no Idea how ti implement this. can someone help me out? Below is my Horizontal Recyclerview adapter.

public class DialogRecyclerViewAdapter extends RecyclerView.Adapter<DialogRecyclerViewAdapter.ViewHolder> {

Context context;

List<UploadImage> dataAdapters;
private SharedPreferences.Editor mSharedPrefEditor;

ImageLoader imageLoader;

public DialogRecyclerViewAdapter(List<UploadImage> getDataAdapter, Context context){

    super();
    this.dataAdapters = getDataAdapter;
    this.context = context;
}

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

    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview, parent, false);

    ViewHolder viewHolder = new ViewHolder(view);

    return viewHolder;
}

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

    final UploadImage dataAdapterOBJ =  dataAdapters.get(position);

    imageLoader = ImageAdapter.getInstance(context).getImageLoader();

    imageLoader.get(dataAdapterOBJ.getImage(),
            ImageLoader.getImageListener(
                    Viewholder.VollyImageView,//Server Image
                    R.drawable.loading_1,//Before loading server image the default showing image.
                    android.R.drawable.ic_dialog_alert //Error image if requested image dose not found on server.
            )
    );

    Viewholder.VollyImageView.setImageUrl(dataAdapterOBJ.getImage(), imageLoader);

    Viewholder.ImageTitleTextView.setText(dataAdapterOBJ.getBrand_name());

    Viewholder.garment_price.setText(dataAdapterOBJ.getGarment_price());


    Viewholder.VollyImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(MihuChatApplication.getInstance().getContext());
            mSharedPrefEditor = sharedPref.edit();
            mSharedPrefEditor.putString(Constants.KEY_FROM_CHAT, "fromChatWIndow").apply();


            Intent i=new Intent(MihuChatApplication.getInstance().getContext(), DetailsNewActivity.class);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            //PACK DATA TO SEND
            i.putExtra("image_title",dataAdapterOBJ.getGarment_name());

            i.putExtra("image_url",dataAdapterOBJ.getImage_full());
            i.putExtra("desc_text", dataAdapterOBJ.getDesc_text());
            //i.putExtra("image_url2", imageLarger);

            i.putExtra("image_price", dataAdapterOBJ.getGarment_price());
            //i.putExtra("disc_price", disc_price);
            //open activity
            MihuChatApplication.getInstance().getApplicationContext().startActivity(i);
        }
    });

}

@Override
public int getItemCount() {

    return dataAdapters.size();
}

class ViewHolder extends RecyclerView.ViewHolder{

    public TextView ImageTitleTextView, garment_price;
    public NetworkImageView VollyImageView ;

    public ViewHolder(View itemView) {

        super(itemView);

        garment_price = (TextView) itemView.findViewById(R.id.garment_price);

        ImageTitleTextView = (TextView) itemView.findViewById(R.id.ImageNameTextView) ;

        VollyImageView = (NetworkImageView) itemView.findViewById(R.id.VolleyImageView) ;

    }
}

}

提前致谢。

推荐答案

尝试以下

这里img_LeftScroll是左图像视图,img_right_scroll是水平列表之间的右图像视图,rv_horizo​​ntal是horizo​​ntallist视图

here img_LeftScroll is the left imageview and img_right_scroll is the right imageview between the horizontal list, rv_horizontal is the horizontallist view

然后点击图像视图做以下,希望它的工作原理

then onclick of the image view do the below, hope it works

 img_LeftScroll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (horizontalLayoutManagaer.findFirstVisibleItemPosition() > 0) {
                rv_horizontal.smoothScrollToPosition(horizontalLayoutManagaer.findFirstVisibleItemPosition() - 1);
            } else {
                rv_horizontal.smoothScrollToPosition(0);
            }

        }
    });

 img_right_scroll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            rv_horizontal.smoothScrollToPosition(horizontalLayoutManagaer.findLastVisibleItemPosition() + 1);
        }
    });

这篇关于水平的Recycler视图与左,右箭头指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆