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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM