您的位置:首页 > 移动开发 > Android开发

Android嵌套问题:ScrollView嵌套RecyclerView完全展示

2018-03-07 12:49 429 查看
实现功能:RecyclerView外层套着ScrollView,使RecyclerView完全展示数据。
实际上ScrollView嵌套RecyclerView,RecyclerView中的数据不会全部展示,显示一行或者两行等情况。
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_ffffff"
android:orientation="vertical"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
android:id="@+id/setting_info_rlv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="false"
android:scrollbars="none" />
</LinearLayout>
</ScrollView>
解决方案:直接给RecyclerView外嵌套一个布局RelativeLayout,再给RelativeLayout设置 属性android:descendantFocusability="blocksDescendants"
<RelativeLayout
android:id="@+id/setting_info_ll_photo"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/setting_info_rlv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="false"
android:scrollbars="none" />
</RelativeLayout>
最后:recyclerview.setnestedscrollingenabled(false);//禁止recyclerView嵌套滑动
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: