我有这样的RecyclerView。我想它只显示最多8个点。但是在ArrayList中有更多8个寻呼机可供更改。
我想当我站在8时,我将页面更改为9,显示数字的第8个点是9?它将变为10,11 ......
这是我的适配器
public RecyclerViewAdapter(Context context, int layout, int number, int viewpagerposition ){
this.context = context;
this.layout = layout;
this.number = number;
this.viewpagerposition = viewpagerposition;
this.numberpage = numberpage;
}
@Override
public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(layout, parent, false);
RecyclerViewAdapter.ViewHolder viewHolder = new RecyclerViewAdapter.ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(RecyclerViewAdapter.ViewHolder holder, int position) {
if(position == viewpagerposition){
holder.itemView.setScaleX(1f);
holder.itemView.setScaleY(1f);
holder.txtrvPager.setText((position+1)+"");
holder.txtrvPager.setBackgroundResource(R.drawable.rvpager_activity);
}
else{
holder.itemView.setScaleX(0.5f);
holder.itemView.setScaleY(0.5f);
holder.txtrvPager.setBackgroundResource(R.drawable.rvpager_inactivity);
}
if(viewpagerposition > 8){
}
}
@Override
public int getItemCount() {
if(number > 8){
return 8;
}else{
return number;
}
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView txtrvPager;
public ViewHolder(View itemView) {
super(itemView);
txtrvPager = (TextView) itemView.findViewById(R.id.txtrvPager);
}
}
答案 0 :(得分:0)
在您的代码中,getItemCount()
方法返回列表大小,只需将其更改为:
@Override
public int getItemCount() {
if(list.size()-1> 8){
return 8;
}else{
return list.size();
}
}
快乐的编码!!