Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v-layout对Recyclerview进行处理后功能基本失效 #45

Closed
hh-pan opened this issue Jul 14, 2017 · 7 comments
Closed

v-layout对Recyclerview进行处理后功能基本失效 #45

hh-pan opened this issue Jul 14, 2017 · 7 comments

Comments

@hh-pan
Copy link

hh-pan commented Jul 14, 2017

使用v-layout对Recyclerview进行处理,使用这个框架基本就不行了,下拉需要拉很长的距离,上拉失效.我以为是我处理的问题,没办法尝试TwinklingRefreshLayout就没问题了.........这算不算是个bug

@scwang90
Copy link
Owner

v-layout 是什么?

@hh-pan
Copy link
Author

hh-pan commented Jul 14, 2017

阿里的virtual-layout框架 https://github.com/alibaba/vlayout

@hh-pan hh-pan closed this as completed Jul 14, 2017
@hh-pan hh-pan reopened this Jul 14, 2017
@scwang90
Copy link
Owner

可以贴出你使用 v-layout 的代码吗?

@hh-pan
Copy link
Author

hh-pan commented Jul 14, 2017

`public class MainFragment extends BaseFragment {

@BindView(R.id.my_recycler_view)
RecyclerView my_recycler_view;
@BindView(refreshLayout)
TwinklingRefreshLayout mTwinklingRefreshLayout;

private String[] name = new String[]{"超级WIFI", "万家超市", "服装城", "美妆城", "皮具城"};

// 测试轮播图数据
private String[] images = {
        "http://img2.3lian.com/2014/f2/37/d/40.jpg",
        "http://d.3987.com/sqmy_131219/001.jpg",
        "http://img2.3lian.com/2014/f2/37/d/39.jpg"
};

private String[] detail = {"值得买", "超划算", "新人福利", "全网秒杀"};
private int[] resource = {R.drawable.test_1, R.drawable.test_2, R.drawable.test_3, R.drawable.test_4};

private ArrayList<String> mDatas;

@Override
protected View initLayout() {
    return View.inflate(mContext, R.layout.wz_main_fragment, null);
}

@Override
protected void init() {
    super.init();

    int marbottom = UiUtils.dipToPx(mContext, 10);

    //v-layout使用
    //1.绑定recyclerView和VirtualLayoutManager
    VirtualLayoutManager layoutManager = new VirtualLayoutManager(mContext);
    my_recycler_view.setLayoutManager(layoutManager);
    //2.设置组件复用回收池
    RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
    my_recycler_view.setRecycledViewPool(viewPool);
    viewPool.setMaxRecycledViews(0, 10);

    //4.数据列表,创建对应的LayoutHelper
    //TODO 1.顶部是输入框,使用吸边布局
    StickyLayoutHelper stickyLayoutHelper = new StickyLayoutHelper();
    stickyLayoutHelper.setStickyStart(true); //设置吸顶

    //TODO 2.设置线性布局,viewpager 广告
    LinearLayoutHelper linearLayoutHelper = new LinearLayoutHelper();
    linearLayoutHelper.setItemCount(1);// 设置布局里Item个数

    //TODO 3.设置线性布局,分类列表
    LinearLayoutHelper llh = new LinearLayoutHelper();
    llh.setItemCount(1);// 设置布局里Item个数
    llh.setMarginBottom(marbottom);

    //TODO 4. 网格布局,商品图片列表
    // 在构造函数设置每行的网格个数
    GridLayoutHelper gridLayoutHelper = new GridLayoutHelper(2);
    gridLayoutHelper.setMarginBottom(marbottom);

    //TODO 5.分割区
    LinearLayoutHelper llh2 = new LinearLayoutHelper();
    llh2.setItemCount(1);// 设置布局里Item个数
    llh2.setMarginBottom(marbottom);

    //TODO 6. 更多商品
    LinearLayoutHelper llh3 = new LinearLayoutHelper();
    llh3.setItemCount(1);// 设置布局里Item个数
    llh3.setMarginBottom(marbottom);

    //TODO 1.
    StickAdapter stick_adapter = new StickAdapter(mContext, stickyLayoutHelper, 1);
    //TODO 2.
    ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(mContext, linearLayoutHelper, 1, images);
    List<CategoryBean> list = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        CategoryBean bean = new CategoryBean();
        bean.imgResource = R.drawable.ic_category_0;
        bean.name = name[i];
        list.add(bean);
    }
    //TODO 3.
    CategoryAdapter categoryAdapter = new CategoryAdapter(mContext, llh, list);

    //TODO 4.商品列表
    List<CategoryBean> iamg = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        CategoryBean bean = new CategoryBean();
        bean.name = detail[i];
        bean.imgResource = resource[i];
        iamg.add(bean);
    }

    GoodsGridviewAdapter goodsGridviewAdapter = new GoodsGridviewAdapter(mContext, gridLayoutHelper, iamg);

    //TODO 5.
    SplitAdapter splitAdapter = new SplitAdapter(mContext, llh2);

    //TODO 6.
    MoreGoodsAdapter moreGoodsAdapter = new MoreGoodsAdapter(mContext, llh3);

    List<DelegateAdapter.Adapter> adapters = new LinkedList<>();
    adapters.add(stick_adapter);
    adapters.add(viewPagerAdapter);
    adapters.add(categoryAdapter);
    adapters.add(goodsGridviewAdapter);
    adapters.add(splitAdapter);
    adapters.add(moreGoodsAdapter);


    // 3. 创建DelegateAdapter对象 & 将layoutManager绑定到DelegateAdapter
    DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager);
    // 4. 将DelegateAdapter.Adapter列表绑定到DelegateAdapter
    delegateAdapter.setAdapters(adapters);
    // 5. 将delegateAdapter绑定到recyclerView
    my_recycler_view.setAdapter(delegateAdapter);

}

@Override
protected void initListener() {
    super.initListener();

    mTwinklingRefreshLayout.setOnRefreshListener(new RefreshListenerAdapter() {
        @Override
        public void onRefresh(final TwinklingRefreshLayout refreshLayout) {
            ToastUtils.showShort(mContext, "刷新界面");
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    refreshLayout.finishRefreshing();
                }
            }, 2000);
        }

        @Override
        public void onLoadMore(final TwinklingRefreshLayout refreshLayout) {
            ToastUtils.showShort(mContext, "加载更多");
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    refreshLayout.finishLoadmore();
                }
            }, 2000);
        }
    });
}

}布局:
<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:id="@+id/my_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="never"/>

</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>`

@scwang90
Copy link
Owner

scwang90 commented Jul 14, 2017

我测试了一下,
LinearLayoutHelper: 线性布局
GridLayoutHelper: Grid布局, 支持横向的colspan
FixLayoutHelper: 固定布局,始终在屏幕固定位置显示
ScrollFixLayoutHelper: 固定布局,但之后当页面滑动到该图片区域才显示, 可以用来做返回顶部或其他书签等
FloatLayoutHelper: 浮动布局,可以固定显示在屏幕上,但用户可以拖拽其位置
ColumnLayoutHelper: 栏格布局,都布局在一排,可以配置不同列之间的宽度比值
SingleLayoutHelper: 通栏布局,只会显示一个组件View
OnePlusNLayoutHelper: 一拖N布局,可以配置1-5个子元素
StickyLayoutHelper: stikcy布局, 可以配置吸顶或者吸底
StaggeredGridLayoutHelper: 瀑布流布局,可配置间隔高度/宽度

全都测试通过,并没有异常现象,表现结果和 TwinklingRefreshLayout 一样

需要确认一下,你使用的版本,还有具体是出现了怎样的错误?可以截图吗?

@hh-pan
Copy link
Author

hh-pan commented Jul 14, 2017

方便加个好友吗,可以把代码给你看看,项目目前只有基本页面没什么内容 qq:526437186 邮箱:526437186@qq.com

@JakeHao
Copy link

JakeHao commented Jan 24, 2018

使用vlayout时,adapter中itemView需要设置LayoutParams,如下:

class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.banner) Banner banner;

public ViewHolder(View itemView) {
  super(itemView);
  itemView.setLayoutParams(mLayoutParams);
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants