布局文件代码
<span style="font-size:18px;"><android.support.v7.widget.RecyclerView android:id="@+id/rv_PeiTaoPicHorizontal" android:layout_width="match_parent" android:layout_height="89dp" android:layout_marginBottom="16dp" android:layout_marginLeft="20dp" ></span>
适配器代码
<span style="font-size:18px;">public class PeiTaoXunJiaDetailRecyAdapter extends RecyclerView.Adapter<PeiTaoXunJiaDetailRecyAdapter.myViewHolder> { private Context context; private List arrayList; public PeiTaoXunJiaDetailRecyAdapter(Context context, List arrayList) { this.context = context; this.arrayList = arrayList; } @Override public myViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { myViewHolder holder = new myViewHolder(View.inflate(parent.getContext(), R.layout.activity_peitaoxunjiarecyitem, null)); return holder; } @Override public void onBindViewHolder(myViewHolder holder, int position) { } @Override public int getItemCount() { return arrayList==null ? 0 : arrayList.size(); } public class myViewHolder extends RecyclerView.ViewHolder { @Bind(R.id.iv_buchongPic) ImageView ivBuchongPic; public myViewHolder(View itemView) { super(itemView); ButterKnife.bind(itemView); } } }</span>
主Activity代码
<span style="font-size:18px;">LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this); linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); rvPeiTaoPicHorizontal.setLayoutManager(linearLayoutManager); rvPeiTaoPicHorizontal.setAdapter(new PeiTaoXunJiaDetailRecyAdapter(getBaseContext(),arrayList));</span>
时间: 2024-10-11 20:46:22