zoukankan      html  css  js  c++  java
  • android -------- 解决RecyclerView显示不全只显示一条item的问题

    布局文件1

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/sv_home_hm"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:scrollbars="none">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recycler_home_model_type"
                android:layout_width="match_parent"
                android:layout_height="65dp"
                android:layout_marginTop="16dp"></androidx.recyclerview.widget.RecyclerView>
    
            <androidx.recyclerview.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"></androidx.recyclerview.widget.RecyclerView>
    
        </LinearLayout>
    
    </ScrollView>

    如图,公司项目有一个界面要用到2个RecyclerView来实现,由上至下垂直排列;

    我的布局是自定义ScrollerView套LinearLayout套的RecyclerView;

    调试接口的时候,发现第三个RecyclerView的展示有问题,就是我们说的显示不全;

    接口明明返回很多数据的,我尝试过很多方法都不行,没有达到想要的结果;

    后来我的解决方案是把RecyclerView外层嵌套的线性布局(LinearLayout)换成相对布局(RelativeLayout),就好了,如下:

    这是垂直冲突的原因

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sv_home_hm"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:scrollbars="none">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recycler_home_model_type"
                    android:layout_width="match_parent"
                    android:layout_height="65dp"
                    android:layout_marginTop="16dp"></androidx.recyclerview.widget.RecyclerView>
    
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recycler_home_model_recommend"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"></androidx.recyclerview.widget.RecyclerView>
        </RelativeLayout>
    </ScrollView>
  • 相关阅读:
    2019.6.30 Spring注解 bean后置处理器和属性赋值
    2019.6.29 Spring注解-Bean的注册
    2019.6.28 Spring注解
    boost基础环境搭建
    动态规划入门一:钢条切割问题
    《剑指offer》读书笔记
    字符串的全排列
    西山居递归面试题
    常见的数据结构
    832. Flipping an Image
  • 原文地址:https://www.cnblogs.com/zhangqie/p/11322020.html
Copyright © 2011-2022 走看看