IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    解决Android 6.0 Recyclerview 在 Scrollview 中不能全部显示

    shendao发表于 2017-03-03 16:56:26
    love 0

    最近项目中发现了一个奇怪的问题,scrollview里面有两个recycleview,这两个recycleview 不需要滑动,只要scrollview可以滑动就行,结果在Android 6.0 以上的机型都不行。以下代码可以直接解决:

    <RelativeLayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:descendantFocusability="blocksDescendants">         <android.support.v7.widget.RecyclerView             android:id="@+id/RecyclerView"             android:layout_width="match_parent"             android:layout_height="wrap_content">         </android.support.v7.widget.RecyclerView>      </RelativeLayout>

    如果要设置recyclerview禁止滑动,可以用以下代码

            GridLayoutManager gridLayout = new GridLayoutManager(this, 2) {             @Override             public boolean canScrollVertically() {                 return false;             }         };          LinearLayoutManager linearLayout = new LinearLayoutManager(this,                 LinearLayoutManager.VERTICAL, false) {             @Override             public boolean canScrollVertically() {                 return false;             }         };          mGridRecyclerview.setLayoutManager(gridLayout);         mLineRecyclerview.setLayoutManager(linearLayout);


沪ICP备19023445号-2号
友情链接