怎么在Android应用中利用RecycleView 实现一个左滑上下分层功能?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
独立Adapter的操作方式
思路: public RCommonSlideAdapter(Object object, List datas, int layoutId, Class clazz, SlideItemHolder handle) {
在onCreateViewHolder中通过反射创建holder,保证数据的操作通过回调函数,交给activity处理
Constructor constructor2 = mClazz.getConstructor(View.class);holder = constructor2.newInstance(v);
上下分层
思路:创建底部xml布局,再通过addView插入顶部view,并交由activity处理,底部布局处理放在adapter中处理。
Constructor constructor = ViewHolderClass.SlideViewHolder.class.getConstructor(View.class); holder = constructor.newInstance(v); View contentView = View.inflate(parent.getContext(), mLayoutId, null); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup .LayoutParams.WRAP_CONTENT); ((ViewHolderClass.SlideViewHolder) holder).mRlSlidContent.addView(contentView, params); Constructor constructor2 = mClazz.getConstructor(View.class); holder = constructor2.newInstance(v); ((ViewHolderClass.SlideViewHolder) holder).mRlSlidContent.getLayoutParams().width = getScreenWidth(parent.getContext());
独立功能项
思路:在xml布局中,不断增加item。并再回调函数中,对每个按钮选择性处理,并可动态添加
<LinearLayout android:id="@+id/linDelete" android:layout_width="100dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_toRightOf="@+id/rlSlidContent" android:orientation="vertical" > <ImageView android:id="@+id/sliding_delete" android:layout_width="30dp" android:layout_height="30dp" android:layout_gravity="center_horizontal" android:src="@drawable/icon_item_delete" /> </LinearLayout>
public class ViewHolderClass { public static class SlideViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.sliding_delete) public ImageView btn_Delete; @BindView(R.id.rlSlidContent) public RelativeLayout mRlSlidContent; @BindView(R.id.linSlideTitle) public LinearLayout mLinSlideTitle; @BindView(R.id.tvSlideTitle) public TextView mTvSlideTitle; public SlideViewHolder(View view) { super(view); ButterKnife.bind(this, view); } } public static class ShopCarViewHolder extends SlideViewHolder { @BindView(R.id.itemTv) public TextView mItemTv; public ShopCarViewHolder(View view) { super(view); } }}
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注编程网行业资讯频道,感谢您对编程网的支持。