RecyclerView加载多布局时,一部分是原生数据, 一部分是网络数据,可能会出现网络数据加载完全后 会挤掉原来的原生ui的位置,
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleview"
android:background="@color/write"
android:layout_width="match_parent"
android:descendantFocusability="blocksDescendants"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
重要的 android:descendantFocusability="blocksDescendants"这句话 出现这种UI界面上移的问题应该是子控件抢占焦点而致,
android:descendantFocusability 大意是:
该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。
属性的值有三种:
-
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
-
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
-
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
所以我们只需要在每一项Item布局的根布局加上android:descendantFocusability=”blocksDescendants”的属性就好了
或者在初始RecyclerView加上android:descendantFocusability=”blocksDescendants”这句话