• 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>
  • 相关阅读:
    K8S 本地 配置 Local PV 实践
    Filebeat 收集K8S 日志,生产环境实践
    K8S 上部署 Redis-cluster 三主三从 集群
    Kubernetes 用户流量接入方案
    给Nginx配置日志格式和调整日期格式
    唇亡齿寒,运维与安全
    Nginx记录用户请求Header到access log
    Kubernetes中利用Kubectl set 让Deployment更新镜像
    故障管理:故障定级和定责
    使用 Elastic 技术栈构建 Kubernetes全栈监控
  • 原文地址:https://www.cnblogs.com/zhangqie/p/11322020.html
Copyright © 2020-2023  润新知