scrollView嵌套recyclerView (再嵌套recyclerView )显示不全

在Android 6.0 解决recyclerview 在 scrollview 中不能全部显示,你可以看到只显示一个条目,解决方法如下:

  • scrollView只嵌套一个recyclerView:
   <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:descendantFocusability="blocksDescendants">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/info_detail_recyclerview"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/white" />
                </RelativeLayout>

在recycleview的父布局加一个属性:

android:descendantFocusability="blocksDescendants"

该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。

属性的值有三种:

beforeDescendants:viewgroup会优先其子类控件而获取到焦点

afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点

blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
当然你可以直接在recycleview加一个RelativeLayout父布局
  • scrollView嵌套recyclerView 再嵌套recyclerView

这是你需要在最外层的recyclerView 执行上面的操作就可以了。

  • 如果这个时候你发现recycleview上下滑动的时候有点卡顿的话,可以使用下面的ScrollView
package tsou.com.equipmentonline.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.widget.ScrollView;

/**
 * 自定义ScrollView嵌套recycleview
 */
public class MyScrollView extends ScrollView {
    private int downX;
    private int downY;
    private int mTouchSlop;

    public MyScrollView(Context context) {
        super(context);
        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    public MyScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    public MyScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent e) {
        int action = e.getAction();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                downX = (int) e.getRawX();
                downY = (int) e.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                int moveY = (int) e.getRawY();
                if (Math.abs(moveY - downY) > mTouchSlop) {
                    return true;
                }
        }
        return super.onInterceptTouchEvent(e);
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值