RecyclerView的使用

本文介绍RecyclerView中LinearLayoutManager的使用注意事项,如不可复用问题,并提供了解决RecyclerView与ScrollView滑动冲突的方法,包括代码配置及布局设置技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、LinearLayoutManager不可以被Recycle重复使用!!!

LinearLayoutManager mLayoutManagerV = new LinearLayoutManager(this);
mLayoutManagerV.setOrientation(LinearLayoutManager.VERTICAL);
2、RecycleView 增加边距 --- 间距的计算,工具类有问题或者麻烦的、 --->  直接在条目里面设置间距。

3、RecyclerView 与ScrollView 滑动冲突

关于滑动冲突的话,一般这种情况下,都是按照ScrollView 去滑动即可。
设置代码 <code> recyclerView.setNestedScrollingEnabled(false);

 

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#eaeaea"
            android:padding="5dp"/>
    </android.support.v4.widget.SwipeRefreshLayout>

 

        recyclerView = (RecyclerView) findViewById(R.id.recycler);
        refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
        refreshLayout.setProgressBackgroundColor(R.color.refresh_bg);

 

    private View initListView(boolean isVer) {
        toolbar.setSubtitle(isVer ?"LinearLayoutManager Vertical":"LinearLayoutManager Horizontal");

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(isVer ? LinearLayoutManager.VERTICAL : LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(new ListAdapter(this,isVer));

       // recyclerView.setHasFixedSize(true);
        recyclerView.setBackgroundColor(Color.WHITE);
        return recyclerView;
    }

 

    @Override
    public void onRefresh() {
        refreshLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                refreshLayout.setRefreshing(false);
            }
        },3000);
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值